반응형 [PCCP] Lv2: 예상 대진표(12985) 해설 문제- 문제 링크: 예상 대진표 해설- 자료구조: - 시간복잡도: (풀이과정)1) 2) 3) 4) 코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: 참가한 인원 수- 같은 번호가 될 때까지 계속해서 2로 나누는 연산: O(logN)더보기#include using namespace std;int solution(int n, int a, int b){ int answer = 0; do { a = (a + 1) / 2; b = (b + 1) / 2; ++answer; } while (a != b); return .. 2024. 12. 24. [PCCP] Lv2: 메뉴 리뉴얼(72411) 해설 문제- 문제 링크: 메뉴 리뉴얼 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: orders의 길이- M: course의 길이- orders의 각 주문을 정렬하는 시간 복잡도는 O(각 order의 길이 * NlogN)이고 각 order의 길이는 최대 10이므로 무시 가능- course만큼 순회하는 반복문에서 각 order의 조합을 만들 때 시간 복잡도는 O(2^N)- 조합의 개수만큼 최댓값을 구하는 과정과 가장 많이 주문된 구성을 찾는 과정의 시간 복잡도는 O(2^N)- course만큼 순회하므로 반복문의 시간 복잡도는 O(M*(2^N)*logM*(2^N))이지만 특정 조건에 맞는 조합이므로 이보다 작음- 최종 시간 복잡도.. 2024. 12. 24. [PCCP] Lv1: 신고 결과 받기(92334) 해설 문제- 문제 링크: 신고 결과 받기 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: report의 길이- report를 순회하고 report_user에 저장하면 시간 복잡도는 O(N)- M: 두번째 반복문에서 reported_user(신고당한 사용자의 정보)의 길이- K: 총 처리 결과 메일 발송 횟수- 두번째 반복문의 시간 복잡도는 O(M*K)- 맨마지막 반복문은 id_list의 길이만큼 순회하나, 문제 조건을 보면 id_list는 최대 개수가 1,000이므로 상수로 무시- 최종 시간 복잡도: O(N + M*K)더보기#include #include #include #include #include using namespac.. 2024. 12. 24. [PCCP] Lv3: 베스트 앨범(42579) 해설 문제- 문제 링크: 베스트 앨범 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: play와 genres의 길이- G: 장르의 수- 각 노래의 장르와 재생 횟수를 맵에 저장하는 시간 복잡도: O(N)- 장르별 총 재생 횟수를 기준으로 정렬하기 위한 시간 복잡도는 O(GlogG)이미만 G는 최대 100이므로 상수로 고려 가능- 각 장르 내에서 노래를 재생 횟수순으로 정렬하기 위한 시간 복잡도: O(NlogN)- 최종 시간 복잡도: O(NlogN)더보기#include #include #include #include using namespace std;bool compareGenre(const pair& a, const pair&.. 2024. 12. 24. [PCCP] Lv2: 오픈 채팅방(42888) 해설 문제- 문제 링크: 오픈 채팅방 코드(C언어)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: record의 길이- 첫번째 반복문에서 record의 모든 항목을 순회하므로 시간 복잡도는 O(N)- 두번째 반복문의 시간 복잡도는 O(N)- 최종 시간 복잡도: O(N)더보기#include #include #include using namespace std;vector solution(vector record) { vector answer; unordered_map uid; for (const auto& line : record) { // 각 record마다 cmd에는.. 2024. 12. 24. [PCCP] Lv2: 할인 행사(131127) 해설 문제- 문제 링크: 할인 행사 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: discount 벡터의 길이- 주어진 want 벡터에 기반하여 10일 동안 할인 상품이 원하는 제품과 일치하는지 확인하므로 시간 복잡도는 O(N)더보기#include #include #include using namespace std;int solution(vector want, vector number, vector discount) { int answer = 0; unordered_map wantMap; // want를 키, number를 값으로 wantMap 선언 for (int i = 0; i discount_10.. 2024. 12. 24. [PCCP] Lv2: 전화번호 목록(42577) 해설 문제- 문제 링크: 전화번호 목록 해설- 자료구조: - 시간복잡도: (풀이과정)1) 2) 3) 4) 코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1) sort()를 이용한 풀이- N: phoneBook의 길이- sort(): O(NlogN)- 반복문은 N번 수행하고 각 substr()은 전화번호 길이만큼 수행할 수 있으므로 전화번호 길이가 M이라면 반복문의 총 시간 복잡도는 O(N*M)- N이 M보다 크므로 M을 상수화하면 반복문의 총 시간 복잡도는 O(N)- 총 시간 복잡도는 O(NlogN)더보기#include #include #include using namespace.. 2024. 12. 24. [PCCP] Lv2: 영어 끝말잇기(12981) 해설 문제- 문제 링크: 영어 끝말잇기 해설- 자료구조: - 시간복잡도: (풀이과정)1) 2) 3) 4) 코드(C언어)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: words의 길이- words의 길이만큼 반복문을 순회하고 각 연산의 시간 복잡도는 O(1)이므로 최종 시간 복잡도는 O(N)더보기#include #include #include using namespace std;vector solution(int n, vector words) { vector answer(2, 0); unordered_set usedWords; usedWords.insert(words[0]);.. 2024. 12. 24. [PCCP] Lv1: 완주하지 못한 선수(42576) 해설 문제- 문제 링크: 완주하지 못한 선수 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: participant의 길이- K: completion의 길이- 참가자의 이름을 해시 테이블에 추가하는 시간 복잡도: O(N)- 완주한 선수들의 이름을 해시 테이블에서 제외하는 연산의 시간 복잡도: O(K)- completion의 최대 길이는 N - 1이므로 K 대신 N - 1로 대체한다면 시간 복잡도는 O(2*(N - 1))- 최종 시간 복잡도: O(N)더보기#include #include #include using namespace std;string solution(vector participant, vector completio.. 2024. 12. 24. [TOEIC Speaking] 목차 Part 01 문장 읽기chapter 01) 유형분석chapter 02) 답변 템플릿chapter 03) 기출문제 Part 02 사진 묘사chapter 01) 유형분석chapter 02) 답변 템플릿chapter 03) 기출문제 Part 03 듣고, 질문에 답하기chapter 01) 유형분석chapter 02) 답변 템플릿chapter 03) 기출문제 Part 04 제공된 정보를 사용하여 질문에 답하기chapter 01) 유형분석chapter 02) 답변 템플릿chapter 03) 기출문제 Part 05 의견 제시하기chapter 01) 유형분석chapter 02) 답변 템플릿chapter 03) 기출문제 Part 06 모의고사chapter 01) Test 01chapter 02) Test 02chapt.. 2024. 12. 24. 이전 1 ··· 6 7 8 9 10 11 12 ··· 61 다음 반응형