본문 바로가기
반응형
[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] 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] Lv2: 기능개발(42586) 해설 문제- 문제 링크: 기능개발 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 각 작업의 배포 가능일 구하기2) 배포 가능일이 첫번째 작업일보다 빠르면 동시에 배포3) 첫번째 작업일보다 늦은 작업일이 존재한다면 2번과정과 유사하게 해당 작업일 이후의 작업들을 묶어서 배포4) 위의 과정 반복 코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: progresses의 길이- day_left 벡터를 생성하기 위한 시간 복잡도: O(N)- day_left의 각 요소를 한 번씩 순회할 때의 시간 복잡도: O(N)- 최종 시간 복잡도: O(N)더보기#include #include .. 2024. 12. 24.
[PCCP] Lv2: 주식 가격(42584) 해설 문제- 문제 링크: 주식 가격 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: prices의 길이- 최악의 경우 각 prices의 원소들은 한 번씩 푸시/팝하므로 시간 복잡도는 O(N)더보기#include #include #include using namespace std;vector solution(vector prices) { // 가격이 떨어지지 않은 기간을 저장한 벡터 vector answer(prices.size()); // 스택에는 prices의 인덱스가 들어감. 이전 가.. 2024. 12. 24.
[PCCP] Lv2: 짝지어 제거하기(12973) 해설 문제- 문제 링크: 짝지어 제거하기 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: s의 길이- 문자열의 모든 문자를 한 번씩 순회하므로 시간 복잡도는 O(N)더보기#include #include using namespace std;int solution(string s) { stack st; for (int i = 0; i solution 2)더보기#include #include #include using namespace std;int solution(string s){ .. 2024. 12. 24.
[PCCP] Lv2: 괄호 회전하기(76502) 해설 문제- 문제 링크: 괄호 회전하기 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: s의 길이- 각 문자열을 순회하면 N개의 케이스가 생기고 각 문자열마다 올바른 괄호 여부를 체크하므로 시간 복잡도는 O(N^2)더보기#include #include #include #include using namespace std;// 닫힌 괄호의 짝을 바로 확인할 수 있도록 맵 선언unordered_map bracketPair = {{')', '('}, {']', '['}, {'}', '{'}};// 인수로 받은 문자열.. 2024. 12. 24.
[PCCP] Lv2: N^2 배열자르기(87390) 해설 문제- 문제 링크: 배열자르기 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#include #include #include int* solution(int n, long long left, long long right) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. int* answer = (int*)malloc(sizeof(int)*(right-left+1)); int quo = 0; int rem = 0; for (long long i = 0; i = rem) answer[i] = quo + 1; .. 2024. 12. 23.
반응형