Skip to content

10-Kaifeel - #41

Open
Kaifeel wants to merge 1 commit into
mainfrom
10-Kaifeel
Open

10-Kaifeel#41
Kaifeel wants to merge 1 commit into
mainfrom
10-Kaifeel

Conversation

@Kaifeel

@Kaifeel Kaifeel commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

문제 링크

μ…”ν‹€λ²„μŠ€

μ†Œμš” μ‹œκ°„

80λΆ„

μ ‘κ·Ό κ³Όμ •

answerλ₯Ό 보면 이게 μ™œ μ΄λ ‡κ²Œ 값이 λ‚˜μ˜¬κΉŒ 생각을 ν•˜κ²Œ λ˜λŠ”λ°, μ΄ν•΄ν•˜λŠ”λ° μ˜€λžœμ‹œκ°„μ΄ κ±Έλ ΈμŠ΅λ‹ˆλ‹€.
콘이 각 크루 쀑 λ²„μŠ€λ₯Ό νƒ‘μŠΉν•  수 μžˆλŠ” μ‹œκ°„μ˜ λŒ€κΈ°μ—΄μ—μ„œ 제일 λ’€μ—μ„œκ²Œ λ§Œλ“€λ©΄ λ©λ‹ˆλ‹€ 쀄을 μ„œλŠ” 것을 보고 μ €λŠ” 큐λ₯Ό 생각 ν–ˆμŠ΅λ‹ˆλ‹€!
νƒ€μž„ν…Œμ΄λΈ”μ„ μ •λ ¬μ‹œμΌœ μ£Όμ–΄μ§„ 쑰건에 λ§žλŠ” κ°€μž₯ 느린 μ‹œκ°„μ„ 찾으면 λ˜λŠ” λ¬Έμ œμž…λ‹ˆλ‹€.

풀이 μ„€λͺ…

(1) νƒ€μž„ν…Œμ΄λΈ”μ„ μ •λ ¬ν•©λ‹ˆλ‹€

sort(timetable.begin(), timetable.end());

(2) 셔틀이 μ˜€λŠ” μ‹œκ°„λ§ˆλ‹€ νƒ€μž„ν…Œμ΄λΈ”μ— μžˆλŠ” 값듀을 λΉΌμ€λ‹ˆλ‹€ μ΄λ•Œ 쑰건은 λ²„μŠ€μ— νƒˆ 수 μžˆλŠ” μΈμ›λ§ŒνΌ μž…λ‹ˆλ‹€

while (!times.empty() && times.front() <= shuttle && member_cnt < m)
{
	lastTime = times.front();
	times.pop_front();

	member_cnt++;
}

(3) 막차가 왔을 λ•Œ 콘이 κ°€μž₯ 늦게 νƒˆ 경우λ₯Ό κ΅¬ν•©λ‹ˆλ‹€ 그리고 μ •μˆ˜λ₯Ό λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•΄μ€λ‹ˆλ‹€

if (bus == n - 1)
{
	if (member_cnt == m)
	{
		ptime = lastTime - 1;
	}
	else
	{
		ptime = shuttle;
	}
}

string hour = to_string(ptime / 60);
string minute = to_string(ptime % 60);

if (hour.size() == 1)
	hour = "0" + hour;

if (minute.size() == 1)
	minute = "0" + minute;

return hour + ":" + minute;

μƒˆλ‘­κ²Œ μ•Œκ²Œ 된 것

전체 μ½”λ“œ

#include <string>
#include <vector>
#include <algorithm>
#include <deque>

using namespace std;

string solution(int n, int t, int m, vector<string> timetable)
{
	string answer = "";
	sort(timetable.begin(), timetable.end());

	deque<int> times;

	for (auto &time : timetable)
	{
		int t = stoi(time.substr(0, 2)) * 60 + stoi(time.substr(3, 2));
		times.push_back(t);
	}

	int shuttle = 9 * 60;
	int ptime = 0;

	for (int bus = 0; bus < n; ++bus)
	{

		int member_cnt = 0;
		int lastTime = 0;

		while (!times.empty() && times.front() <= shuttle && member_cnt < m)
		{
			lastTime = times.front();
			times.pop_front();

			member_cnt++;
		}

		if (bus == n - 1)
		{
			if (member_cnt == m)
			{
				ptime = lastTime - 1;
			}
			else
			{
				ptime = shuttle;
			}
		}

		shuttle += t;
	}

	string hour = to_string(ptime / 60);
	string minute = to_string(ptime % 60);

	if (hour.size() == 1)
		hour = "0" + hour;

	if (minute.size() == 1)
		minute = "0" + minute;

	return hour + ":" + minute;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant