문제 링크:
카카오 신입 공채 1차 코딩 테스트 문제 해설
‘블라인드’ 전형으로 실시되어 시작부터 엄청난 화제를 몰고 온 카카오 개발 신입 공채. 그 첫 번째 관문인 1차 코딩 테스트가 지난 9월 16일(토) 오후 2시부터 7시까지 장장 5시간 동안 온라인으로 치러졌습니다. 지원자들의 개발 능력을 잘 검증하기 위해 출제 위원들이 한 땀 한 땀 독창적이고 다양한 문제들을 만들어 냈고 문제에 이상은 없는지, 테스트케이스는 정확한지 풀어보고 또 풀어보며 […]
tech.kakao.com
입출력:
TC# | 입력 | 출력 |
1 | 1 1 5 08:00 08:01 08:02 08:03 |
09:00 |
2 | 2 10 2 09:10 09:09 08:00 |
09:09 |
3 | 2 1 2 09:00 09:00 09:00 09:00 |
08:59 |
4 | 1 1 5 00:01 00:01 00:01 00:01 00:01 |
00:00 |
5 | 1 1 1 23:59 |
09:00 |
6 | 10 60 45 23:59 23:59 23:59 23:59 23:59 23:59 23:59 23:59 23:59 23:59 23:59 23:59 23:59 23:59 23:59 23:59 |
18:00 |
코드:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int n, t, m;
string crew_time;
vector<pair<int, int>> crew_times;
vector<pair<int, int>> bus_queue[10];
pair<int, int> add(pair<int, int> a, int b) {
int min = a.second + b;
return make_pair(a.first + min / 60, min % 60);
}
pair<int, int> sub1(pair<int, int> a) {
if (a.second == 0)
return make_pair(a.first - 1, 59);
return make_pair(a.first, a.second - 1);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> t >> m;
while (!cin.eof()) { // crew arrival time
cin >> crew_time;
crew_times.emplace_back(10 * (crew_time[0] - '0') + crew_time[1] - '0', 10 * (crew_time[3] - '0') + crew_time[4] - '0');
}
sort(crew_times.begin(), crew_times.end()); // sort crew arrival time
pair<int, int> bus_time = { 9, 0 };
int next_crew = 0;
for (int i = 0; i < n; ++i) { // assign to time slot
for (int j = 0; j < m; ++j) { // assign up to m crews
if (next_crew < crew_times.size() && crew_times[next_crew] <= bus_time)
bus_queue[i].push_back(crew_times[next_crew++]);
else
break;
}
bus_time = add(bus_time, t);
}
pair<int, int> ans = { 9, 0 };
if (bus_queue[n - 1].size() == m) {
ans = sub1(bus_queue[n - 1][m - 1]);
}
else {
ans = add(ans, (n - 1) * t);
}
if (ans.first < 10) {
cout << '0';
}
cout << ans.first << ':';
if (ans.second < 10) {
cout << '0';
}
cout << ans.second;
return 0;
}