문제 설명
09:00
부터 총 n
회 t
분 간격으로 역에 도착하며, 하나의 셔틀에는 최대 m
명의 승객이 탈 수 있다.09:00
에 도착한 셔틀은 자리가 있다면 09:00
에 줄을 선 크루도 탈 수 있다.풀이
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int tTom(string s)
{
int ret;
int H, M;
H = s[0] - '0';
H = H * 10 + (s[1] - '0');
M = s[3] - '0';
M = M * 10 + (s[4] - '0');
ret = H * 60 + M;
return ret;
}
//첫 셔틀은 9시 정각에 있다
string solution(int n, int t, int m, vector<string> timetable)
{
string ret = "";
vector<vector<int>> shuttle(n);
vector<int> shuttleTime = { 540 };
for (int i = 1; i < n; i++)
{
shuttleTime.push_back(shuttleTime.back() + t);
}
sort(timetable.begin(), timetable.end());
int arrive;
for (int i = 0; i < timetable.size(); i++)
{
arrive = tTom(timetable[i]);
for (int j = 0; j < n; j++)
{
if (arrive <= shuttleTime[j] && shuttle[j].size() < m)
{
shuttle[j].push_back(arrive);
break;
}
}
}
int result = 0;
if (shuttle.back().size() == m)
{
result = shuttle.back().back() - 1;
}
else
{
result = shuttleTime.back();
}
int H = result / 60;
int M = result % 60;
if (H < 10)
{
ret += '0';
}
ret += to_string(H);
ret += ':';
if (M < 10)
{
ret += '0';
}
ret += to_string(M);
return ret;
}