반응형 [PCCP] Lv2: 롤케이크 자르기(132265) 해설 문제- 문제 링크: 롤케이크 자르기 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: topping의 길이- topping의 길이만큼 반복문을 수행하므로 시간 복잡도는 O(N)- 내부 연산들은 모두 O(1)- 최종 시간 복잡도: O(N)더보기#include #include #include #include using namespace std;int solution(vector topping) { int answer = 0; // 남아있는 각 토핑의 개수 unordered_map topping_cnt; // 절반에 속한 토핑의 종류 unordered_set half_topping; // 카운터에 각 토핑의 개수를 저장.. 2024. 12. 25. [PCCP] Lv2: 이진 변환 반복하기(70129) 해설 문제- 문제 링크: 이진 변환 반복하기 해설- 자료구조: - 시간복잡도: (풀이과정)1) 2) 3) 4) 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: 주어진 수- while 문에서 N이 1이 될 때까지 2로 나누므로 시간 복잡도는 O(logN)- count() 호출시 필요한 시간 복잡도는 O(N)- 최종 시간 복잡도: O(NlogN)더보기#include #include #include #include using namespace std;vector solution(string s) { int transforms = 0; int removedZeros = 0; // s가 "1"이 될 때까지 계속 반복 .. 2024. 12. 25. [PCCP] Lv3: 사라지는 발판(92345) 해설 문제- 문제 링크: 사라지는 발판 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: board의 가로 길이- M: board의 세로 길이- 각 위치에서 상하좌우 4개의 경우의 수가 있으므로 최종 시간 복잡도는 O(4^(M*N))더보기#include #include using namespace std;const int dx[4] = {0, 0, -1, 1};const int dy[4] = {-1, 1, 0, 0};int n, m;// 현재 위치가 게임판을 벗어나는 확인bool isOutOfBounds(int r, int c) { return r = n || c = m; }int playGame(vector> &board, in.. 2024. 12. 25. [PCCP] Lv3: 외벽 점검(60062) 해설 문제- 문제 링크: 외벽 점검 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: dist의 길이- M: weak의 길이- weak 벡터에 항목을 추가하는 연산의 시간복잡도 O(M)- 이후 반복문에서 모든 weak 지점을 순회(M)하며 친구들의 순열을 모두 확인(N!)- 현재 투입된 친국 다음 weak까지 갈 수 있는지 체크하기 위한 시간복잡도는 O(M)- 최종시간 복잡도: O(M^2 * N!)더보기#include #include using namespace std;int solution(int n, vector weak, vector dist) { int length = weak.size(); // weak 배열 .. 2024. 12. 25. [PCCP] Lv2: 양궁대회(92342) 해설 문제- 문제 링크: 양궁대회 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- 0-10점 각 과녁에 화살을 맞힌다/못 맞힌다 두 상태가 있으므로 시간복잡도는 O(2^11)더보기#include using namespace std;vector answer;vector ryan(11, 0);int maxScore = -1;// 어피치와 라이언의 점수 차이 계산int calcScoreDiff(const vector &apeach) { int scoreApeach = 0; int scoreLion = 0; for (int i = 0; i = ryan[i]) scoreApeach += 10 - i;.. 2024. 12. 25. [PCCP] Lv2: N-Queen(12952) 해설 문제- 문제 링크: N-Queen 해설- 자료구조: - 시간복잡도: 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: 퀸의 개수- 각 행에 퀸을 놓는 방법의 경우의 수는 N!이고, 시간 복잡도는 O(N!)더보기#include #include using namespace std;// 현재 행에 이미 다른 퀸이 있는지 확인bool isSameRow(int placedRow, int currentRow) { return placedRow == currentRow; }// 대각선에 다른 퀸이 있는지 확인bool isDiagonalAttack(int placedCol, int placedRow, int currentCol, int .. 2024. 12. 25. [PCCP] Lv2: 피로도(87946) 해설 문제- 문제 링크: 피로도 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: 던전의 개수- 최악의 경우 모든 경로를 탐색하므로 경우의 수는 N*(N-1)*...*1이므로 시간복잡도는 O(N!)더보기#include #include using namespace std;int maxDepth = 0;bool visited[8] = {false,};// 던전의 최대 방문수를 갱신하면서 깊이 우선 탐색으로 던전 탐색void exploreDungeon(int depth, int power, vector> &dungeons) { if (maxDepth power) continue; /.. 2024. 12. 25. [PCCP] Lv2: 전력망을 둘로 나누기(86971) 해설 문제- 문제 링크: 전력망을 둘로 나누기 해설- 자료구조: - 시간복잡도: (풀이과정)1) 2) 3) 4) 코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (C#)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (Java)solution 1)- N은 송전탑의 개수- 깊이우선탐색을 이용하여 한 번에 탑을 구하므로 시간 복잡도는 O(N)- N이 100이하이므로 O(N^2)으로 풀이 가능더보기import ja.. 2024. 12. 25. [PCCP] Lv3: 경주로 건설(67259) 해설 문제- 문제 링크: 경주로 건설 해설- 자료구조: - 시간복잡도: (풀이과정)1) 2) 3) 4) 코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (C#)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (Java)solution 1)- N: 보드의 한 변의 길이- 너비 우서 탐색은 N * N개의 노드를 탐색하고 네 방향을 고려하므로 시간 복잡도는 O(N^2)더보기import java.util.ArrayD.. 2024. 12. 25. [PCCP] Lv2: 배달(12978) 해설 문제- 문제 링크: 배달 해설- 자료구조: - 시간복잡도: (풀이과정)1) 2) 3) 4) 코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (C#)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (Java)solution 1)- E: road의 길이- 그래프를 추가할 때 시간 복잡도는 O(E)- 다익스트라 알고리즘은 우선순위 큐를 활용했으므로 O((N + E)logN)- 마지막 결과 리스트를 순회하며 K.. 2024. 12. 25. 이전 1 2 3 4 5 6 7 다음 반응형