정신과 시간의 방

전체 글 396

카테고리 설명
청춘의 기록
  • 풀이코드#includeusing namespace std;int main(int argc, char** argv){ int test_case; int T; cin>>T; for(test_case = 1; test_case > numbers[i]; if (numbers[i] % 2 == 1) { sum += numbers[i]; } } cout

  • 보호되어 있는 글입니다.

  • 문제 풀이코드#include #include #include using namespace std;string input;string front_half;string middle_char;string back_half;string result;int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> input; int count[26] = { 0, }; for (int i = 0; i 요약노트1. 풀이 알고리즘 문자열, 구현, 그리디2. 풀이 전체 흐름 요약 1) 알파벳 빈도수 계산2) 팰린드롬 생성 가능성 확인- count 배열을 A부터 Z까지 순회하며 개수가 홀수인 알파벳을 찾음- 만약 홀수인 알파벳을 처음 발견했다면 해당 알파벳을 middle_cha..

  • 문제상황유니티에서 Input.GetMouseButtonDown(0)를 사용했는데 실행시 InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings. 라는 오류 메시지가 발생했다.문제해결상단 메뉴에서 Edit - Project Settings 클릭 왼쪽 메뉴창에서 Player - Active Input Handling을 Both로 설정하면 정상적으로 입력 된다.

  • 문제 (https://www.acmicpc.net/problem/10988) 풀이코드#include using namespace std;string input;int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> input; int maxIndex = input.length(); int targetIndex = maxIndex - 1; int flag = 0; for (int i = 0; i 요약노트1. 풀이 알고리즘구현, 문자열2. 시간복잡도 O(N) 3. 공간복잡도 O(N)

  • 문제 (https://www.acmicpc.net/problem/11660) 풀이코드#include #include using namespace std;int main(){ ios::sync_with_stdio(0); cin.tie(0); int N, M; cin >> N >> M; // 2차원 누적 합 배열 (prefix sum board) // 원본 배열(board)을 생략하여 메모리 최적화 vector> prefix_board(N + 1, vector(N + 1, 0)); // 누적 합 배열 생성 for (int r = 1; r > num; prefix_board[r][c] = prefix_board[r][c - 1] + prefix_board[r - 1][c] ..

  • 문제 (https://www.acmicpc.net/problem/2108) 풀이코드#include #include #include #include #include using namespace std;int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector a(n); vector freq(8001, 0); // [-4000,4000] -> [0,8000] long long sum = 0; int mn = INT_MAX, mx = INT_MIN; for (int i = 0; i > x; a[i] = x; sum += x; freq[x +..

  • 유니티에서 TextMeshPro로 되어 있는 Text, Button에 대해서 폰트를 적용하려면TTF 등의 폰트 확장자를 TMP 파일로 변환해야 한다. Window -> TextMeshPro -> FontAssetCreator 경로로 들어가서 Source Font에 사용하고 싶은 폰트 파일을 지정한다.이때 주의 할 점은 한글로 폰트를 사용하고자 한다면 올바른 출력을 위해서 범위를 조정해줘야 한다.Character Set에서 Custom Range를 설정하고 바로 아래 Character Sequence에서 32-126,44032-55203,12593-12643,8200-9900위와 같이 범위를 수정해 준 다음, 정상적으로 생성되고 나면 Generate Font Atlas -> Save As 클릭으로 저장..

작성일
2025. 11. 9. 12:01
작성자
risehyun
  • 풀이코드
#include<iostream>

using namespace std;

int main(int argc, char** argv)
{
	int test_case;
	int T;

	cin>>T;

	for(test_case = 1; test_case <= T; ++test_case)
	{
      
        int numbers[11];
    	int sum = 0;
        
		for (int i = 1; i < 11; ++i)
        {
            cin >> numbers[i];
            
            if (numbers[i] % 2 == 1)
            {
				sum += numbers[i];
            }
        }
		cout << '#' << test_case << ' ' << sum << '\n';
	}
  
	return 0;
}
작성일
2025. 10. 12. 18:45
작성자
risehyun
작성일
2025. 10. 11. 15:32
작성자
risehyun
  • 문제

 

  • 풀이코드
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string input;
string front_half;
string middle_char;
string back_half;
string result;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> input;
	
	int count[26] = { 0, };
	
	for (int i = 0; i < (int)input.length(); ++i)
	{
		count[input[i] - 'A']++;
	}
	
	for (int i = 0; i < 26; ++i)
	{
		if (count[i] % 2 == 1)
		{
			if (!middle_char.empty())
			{
				cout << "I'm Sorry Hansoo" << '\n';
				return 0;
			}
			middle_char += (char)(i + 'A');
		}
		
		for (int j = 0; j < count[i] / 2; ++j)
		{
			front_half += (char)(i + 'A');
		}
	}
	
	back_half = front_half;
	reverse(back_half.begin(), back_half.end());
	
	result = front_half + middle_char + back_half;
	
	cout << result << '\n';
	
	return 0;
}

 

 

  • 요약노트
    1. 풀이 알고리즘
    문자열, 구현, 그리디

    2. 풀이 전체 흐름 요약
    1) 알파벳 빈도수 계산
    2) 팰린드롬 생성 가능성 확인
    - count 배열을 A부터 Z까지 순회하며 개수가 홀수인 알파벳을 찾음
    - 만약 홀수인 알파벳을 처음 발견했다면 해당 알파벳을 middle_char 변수에 저장
    - middle_char가 이미 채워져 있는데 또 다른 홀수 알파벳이 발견되면 팰린드롬 생성이 불가능하므로 프로그램을 종료
    3) 팰린드롬 조립
    - front_half라는 빈 문자열을 준비
    - A부터 Z까지 순회하며, 각 알파벳을 (개수 / 2) 만큼 front_half에 추가
    (이 과정을 통해 front_half는 자연스럽게 사전순으로 가장 앞서는 조합이 됨)
    - front_half를 back_half에 복사한 뒤 reverse() 함수를 이용해 back_half의 순서를 뒤집음
    - 최종 결과 생성 및 출력: front_half + middle_char + back_half 순서로 문자열을 합쳐 최종 결과(result)를 만들고 출력

    3. 이번 문제를 풀며 새로 배운 지식
    - 팰린드롬의 조건: 문자열을 재배치하여 팰린드롬을 만들 수 있으려면 개수가 홀수인 알파벳이 1개 이하여야 함
    - 빈도수 배열 활용
    - C++ 배열의 초기화: int arr[N];과 같이 지역 변수로 배열을 선언만 하면 쓰레기 값으로 채워지므로 초기화 필요
    - std::string 상태 확인: C++의 string 객체가 비어있는지 확인할 때는 compare() 함수보다 !str.empty() 와 같이 명시적이고 안전한 empty() 메소드를 사용하는 것이 더 좋은 방법임

    4. 시간 복잡도
    - O(N) (N은 입력 문자열의 길이)
    1) 입력 문자열을 순회하며 알파벳 개수를 세는 데 O(N)이 걸림
    2) count 배열을 순회하며 front_half와 middle_char를 만드는 과정에 안쪽 for문의 총 반복 횟수는 N/2에 비례하므로 O(N)
    3) reverse() 함수는 front_half의 길이(N/2)에 비례하므로 O(N)
    4) 문자열을 합치는 과정 또한 전체 길이에 비례하므로 O(N)
    따라서 가장 큰 영향을 미치는 항은 N이므로, 전체 시간 복잡도는 O(N)

    5. 공간 복잡도
    O(N) (N은 입력 문자열의 길이)
    1) count 배열은 입력 길이 N과 상관없이 항상 크기가 26이므로 O(1)의 공간을 차지
    2) 하지만 input, front_half, back_half, result와 같은 문자열 변수들은 입력 문자열의 길이에 비례하여 메모리를 사용
    따라서 전체 공간 복잡도는 N에 비례하는 O(N)
카테고리
작성일
2025. 10. 10. 17:38
작성자
risehyun
  • 문제상황
    유니티에서 Input.GetMouseButtonDown(0)를 사용했는데 실행시 InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings. 라는 오류 메시지가 발생했다.

  • 문제해결
    상단 메뉴에서 Edit - Project Settings 클릭

 

왼쪽 메뉴창에서 Player - Active Input Handling을 Both로 설정하면 정상적으로 입력 된다.

 

작성일
2025. 10. 3. 16:25
작성자
risehyun

 

 

  • 풀이코드
#include <iostream>
using namespace std;

string input;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> input;
	
	int maxIndex = input.length();
	
	int targetIndex = maxIndex - 1;
	int flag = 0;
	
	for (int i = 0; i < targetIndex; i++)
	{
		if (input[i] != input[targetIndex])
		{
			flag = 1;
			break;
		}
		targetIndex--;
	}
	
	if (flag == 1)
	{
		cout << 0;
	}
	else
	{
		cout << 1;
	}

	return 0;
}

 

 

  • 요약노트
    1. 풀이 알고리즘
    구현, 문자열

    2. 시간복잡도
    O(N)

    3. 공간복잡도
    O(N)

작성일
2025. 9. 23. 13:49
작성자
risehyun

 

 

  • 풀이코드
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int N, M;
	cin >> N >> M;
	
	// 2차원 누적 합 배열 (prefix sum board)
	// 원본 배열(board)을 생략하여 메모리 최적화
	vector<vector<int>> prefix_board(N + 1, vector<int>(N + 1, 0));
	
	// 누적 합 배열 생성
	for (int r = 1; r <= N; ++r) // row (행)
	{
		for (int c = 1; c <= N; ++c) // column (열)
		{
			int num;
			cin >> num;
			
			prefix_board[r][c] = prefix_board[r][c - 1] + prefix_board[r - 1][c]
			                   - prefix_board[r - 1][c - 1] + num;
		}
	}
	
	// M개의 쿼리 처리
	for (int i = 0; i < M; ++i)
	{
		int r1, c1, r2, c2;
		cin >> r1 >> c1 >> r2 >> c2;
		
		// 누적 합을 이용하여 구간 합 계산
		int result = prefix_board[r2][c2] - prefix_board[r1 - 1][c2]
		           - prefix_board[r2][c1 - 1] + prefix_board[r1 - 1][c1 - 1];
		
		cout << result << '\n';
	}
	
	return 0;
}

 

  • 요약노트

    1. 풀이 알고리즘
    2차원 누적 합 (2D Prefix Sum)

    2. 풀이 전체 흐름 요약

    1) 표의 크기 N과 합을 구하는 횟수 M을 입력받음
    2) 누적 합을 저장할 (N+1) x (N+1) 크기의 2차원 배열 prefix_board를 생성하고 0으로 초기화
    3) 이중 for 문을 이용해 N x N 크기의 표에 들어갈 숫자들을 입력받으면서 동시에 누적 합 배열 prefix_board를 다음 공식으로 채워나감 =>  S[r][c] = S[r-1][c] + S[r][c-1] - S[r-1][c-1] + (현재 입력받은 값)
    4) M번 반복하는 for 문을 실행하여 각 쿼리를 처리
    5) 각 쿼리마다 좌표 r1, c1, r2, c2를 입력받고 아래 공식을 사용해 구간 합을 O(1) 시간 내에 계산
    6) 결과 = S[r2][c2] - S[r1-1][c2] - S[r2][c1-1] + S[r1-1][c1-1], 계산된 결과를 즉시 출력

    3. 시간 복잡도

    O(N²)
    - 누적 합 값을 저장하기 위해 (N+1) x (N+1) 크기의 2차원 배열 prefix_board를 사용

    - 이 배열의 크기는 N에 따라 제곱으로 증가하므로 공간 복잡도는 O(N²)가 됨

    4. 공간 복잡도
    O(N² + M)
    - 누적 합 배열을 생성하는 데 N x N 크기의 이중 반복문이 필요하므로 O(N²) 시간이 소요

    - 이후 M개의 쿼리를 처리할 때, 각 쿼리는 O(1)의 시간이 걸리므로 총 O(M) 시간이 소요
    -  따라서 전체 시간 복잡도는 이 둘을 더한 O(N² + M) 가 됨
작성일
2025. 9. 22. 12:02
작성자
risehyun

 

 

  • 풀이코드
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;

int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n; 
    cin >> n;

    vector<int> a(n);
    vector<int> freq(8001, 0);      // [-4000,4000] -> [0,8000]
    long long sum = 0;
    int mn = INT_MAX, mx = INT_MIN;

    for (int i = 0; i < n; ++i) 
	{
        int x;
        cin >> x;
        a[i] = x;
        sum += x;
        freq[x + 4000]++;
        mn = min(mn, x);
        mx = max(mx, x);
    }

    sort(a.begin(), a.end());

    // 1) 산술평균 (반올림)
    int mean = static_cast<int>(std::round(static_cast<double>(sum) / n));

    // 2) 중앙값
    int median = a[n / 2];

    // 3) 최빈값 (여러 개면 두 번째로 작은 값)
    int maxFreq = *max_element(freq.begin(), freq.end());
    int modeValue = 0;
    {
        int found = 0; // 몇 번째 모드인지 카운트
        for (int i = 0; i <= 8000; ++i) 
		{
            if (freq[i] == maxFreq) 
			{
                // 첫 번째 모드면 그냥 기록, 두 번째 모드가 나오면 그 값을 선택
                modeValue = i - 4000;
                found++;
                if (found == 2) break; // 두 번째로 작은 값에서 멈춤
            }
        }
    }

    // 4) 범위 
    int rangeVal = mx - mn;

    cout << mean << '\n'
         << median << '\n'
         << modeValue << '\n'
         << rangeVal << '\n';

    return 0;
}
카테고리
작성일
2025. 9. 16. 10:40
작성자
risehyun

유니티에서 TextMeshPro로 되어 있는 Text, Button에 대해서 폰트를 적용하려면

TTF 등의 폰트 확장자를 TMP 파일로 변환해야 한다.

 

Window -> TextMeshPro -> FontAssetCreator 경로로 들어가서

 

 

Source Font에 사용하고 싶은 폰트 파일을 지정한다.
이때 주의 할 점은 한글로 폰트를 사용하고자 한다면 올바른 출력을 위해서 범위를 조정해줘야 한다.
Character Set에서 Custom Range를 설정하고

 

 

바로 아래 Character Sequence에서


32-126,44032-55203,12593-12643,8200-9900

위와 같이 범위를 수정해 준 다음, 정상적으로 생성되고 나면 Generate Font Atlas -> Save As 클릭으로 저장

 

 

이제 원하는 곳에 폰트를 사용할 수 있다.