Make Unreal REAL.
article thumbnail
Level 2. 가장 큰 정사각형 찾기

Level 2. 가장 큰 정사각형 찾기 모든 점을 확인하며 가장 큰 정사각형을 찾기 때문에, 중복으로 인해 시간 초과가 발생했다. // 이 풀이는 시간 초과가 발생한다. #include #include #include using namespace std; int checkSquare(vector& board, int r, int c) { int n = 0; int R = board.size(), C = board.front().size(); while (r < R && c < C) { for (int i = r - n; i

article thumbnail
Level 2. 게임 맵 최단거리

Level 2. 게임 맵 최단거리 처음엔 DFS를 시도해 시간 초과가 발생했다. 내가 왔던 방향이 아닌 방향으로 계속 진행하면서 최소 비용을 갱신하는 방식이다. // 이 풀이는 시간 초과가 발생한다. #include #include #include #include using namespace std; enum class DIR { Up = 1, Down = 2, Left = 4, Right = 8 }; void rDFS(vector& maps, int i, int j, int from, int cost) { int n = maps.size(), m = maps.front().size(); if (i < 0 || n

article thumbnail
Level 0. 간단한 논리 연산

Level 0. 간단한 논리 연산 #include using namespace std; bool solution(bool x1, bool x2, bool x3, bool x4) { return (x1 | x2) & (x3 | x4); }

article thumbnail
Level 2. 줄 서는 방법

Level 2. 줄 서는 방법 next_permutation() 함수로 간단하게 해결하면 시간 초과가 발생한다. // 이 풀이는 시간 초과가 발생한다. #include #include #include #include using namespace std; vector solution(int n, long long k) { vector answer(n); iota(answer.begin(), answer.end(), 1); while (--k) next_permutation(answer.begin(), answer.end()); return answer; } #include #include #include using namespace std; long long factorial(int n) { return (n

article thumbnail
Level 2. 하노이의 탑

Level 2. 하노이의 탑 유명하고 전형적인 하노이의 탑 알고리즘이다. 3개를 A에서 B를 거쳐 C로 옮긴다고 할 때, A에 있는 2개를 C를 거쳐 B로 옮긴다. A에 남은 1개를 C로 옮긴다. 1단계에서 B로 옮겼던 2개를 A를 거쳐 C로 옮긴다. #include #include #include using namespace std; vector solution(int n, int from, int through, int to) { if (n == 1) return {{from, to}}; vector result = solution(n - 1, from, to, through); result.emplace_back(vector{from, to}); vector t = solution(n - 1, th..

article thumbnail
Level 2. 모음사전

Level 2. 모음사전 #include using namespace std; bool rDFS(string s, string& word, int& answer) { const static string alphabets[] = {"A", "E", "I", "O", "U"}; ++answer; if (s == word) return true; else if (s.length() == 5) return false; for (const string& alpha : alphabets) if (rDFS(s + alpha, word, answer)) return true; return false; } int solution(string word) { int answer = 0; const string alphabe..

검색 태그