본문 바로가기

Programmers/효율성 시간초과 모음

(5)
[Programmers] 호텔 방 배정 #include #include #include using namespace std; typedef long long ll; vector solution(long long k, vector num) { vector answer; map roomMap; map ::iterator it; for (int i = 0; i < num.size(); i++) { if (roomMap[num[i]] == 0) { roomMap[num[i]] = i+1; //0을 피하기 위해 answer.push_back(num[i]); } else { //원하는 방이 이미 배정된 경우 ll idx = num[i]+1; while(1) { if (roomMap[idx] == 0) break; idx++; } roomMap[idx] ..
[프로그래머스] 무지의 먹방 라이브 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #include #include #include #include using namespace std; typedef pair pp; bool compare(const pp &a, const pp &b) { return a.second second; } } return -1 ; } http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scri..
[프로그래머스] 짝지어 제거하기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include #include #include using namespace std; //효율성 테스트 시간초과 int solution(string s) { int answer = 0; int i = 0; while(i
[프로그래머스] 최고의 집합 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include #include #include using namespace std; typedef long long ll; //효율성 테스트 시간 초과 vector solution(int n, int s) { vector answer; // vector eles; if (n == 1 && s == 1) { answer.push_back(1); return answer; } else if (n > s){ answer.push_back(-1); return answer; } else { for (int i = n; i >= 1; i--) { int num =..
[프로그래머스] 기지국 설치 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include #include #include using namespace std; typedef pair pp; //효율성 테스트 시간 초과 int solution(int n, vector stations, int w) { int answer = 0; vector apart(n, 0); //인덱스, 설치 됐는지 아닌지 확인 for (int i = 0; i