정신과 시간의 방

코딩테스트 203

카테고리 설명
  • 문제 풀이코드#include #include #include using namespace std;int n;int m;// 상하좌우 4방향 이동 벡터 (dy, dx)int dy[4] = { -1, 1, 0, 0 };int dx[4] = { 0, 0, -1, 1 };// temp_board: 시뮬레이션(벽 설치 + 바이러스 확산)에 사용할 임시 보드// board : 입력으로 주어진 원본 보드(훼손 금지)int temp_board[10][10];int board[10][10];int ans; // 가능한 안전 영역의 최댓값// 멀티소스 BFS: temp_board에서 모든 바이러스(2)를 동시에 출발시켜 확산void BFS(){ queue> q; // 1) 시작점 수집: 현재 temp_board..

  • 문제 풀이코드#include #include #include using namespace std;int N;int K;queue q;const int MAX = 100000; int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> N >> K; // 최단 시간 vector dist(MAX + 1, -1); // 최단 경로 수 vector ways(MAX + 1, 0); // 시작점인 N을 기준으로 초기 세팅 dist[N] = 0; ways[N] = 1; q.push(N); // 주어진 조건에 따라 BFS 실행 while(!q.empty()) { int x = q.front(); q.pop(); // dist[K]가 정해졌다면 // 최..

  • 문제 풀이코드#include using namespace std;int h;int w;string s;int time[101][101];int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w; for (int y = 0; y > s; for (int x = 0; x

  • 문제 풀이코드#include #include #include #include using namespace std;// 숫자 문자열의 앞에 붙은 '0'을 제거하는 함수// 모두 0일 경우에는 "0"을 반환string normalize(const string& s){ size_t p = s.find_first_not_of('0'); // 처음으로 0이 아닌 문자의 위치 찾기 if (p == string::npos) return "0"; // 전부 0이면 "0" 반환 return s.substr(p); // 맨 앞의 0들을 제거한 부분 문자열 반환}int main(){ ios::sync_with_stdio(0); cin.tie(0); int n = 0; cin >> n; c..

  • 문제 (https://www.acmicpc.net/problem/10808) 풀이코드#include using namespace std;string input;int bucket[26];int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> input; for (char c : input) { bucket[c - 'a']++; } for (int i = 0; i

  • 문제 (https://www.acmicpc.net/problem/9375) 풀이코드#include #include #include using namespace std;int t;int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { int n; cin >> n; unordered_map closet(n); for (int i = 0; i > name >> type; ++closet[type]; } long long ways = 1; for (auto& clothes : closet) { ways *= (clothes.second + 1); } cout

  • 문제 (https://www.acmicpc.net/problem/17219) 풀이코드#include #include using namespace std;int N;int M;int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> N >> M; unordered_map table(N); while (N--) { string site = ""; string password = ""; cin >> site >> password; table[site] = password; } while (M--) { string target = ""; cin >> target; cout

  • 문제 https://www.acmicpc.net/problem/14626 풀이코드#include using namespace std;char isbn[13];int answer;int main(){ ios::sync_with_stdio(0); cin.tie(0); for (int i = 0; i > isbn[i]; } int star = -1; // * 위치 int sum = 0; // 앞 12자리에 대한 가중합 // 체크숫자인 맨 마지막 13번째 숫자 M와 *이 있는 곳을 제외한 가중치 계산 for (int i = 0; i