답안 #746193

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746193 2023-05-21T20:53:07 Z JellyTheOctopus Job Scheduling (CEOI12_jobs) C++17
100 / 100
209 ms 13504 KB
#include <bits/stdc++.h>
using namespace std;

int N, D, M;
vector<int> arr[100001];

bool check(int x) {
	queue<int> q;
	int wait = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < (int)arr[i].size(); j++) {
			q.push(i);
		}
		if (!q.empty()) {
			wait = max(wait, i-q.front());
		}
		for (int j = 0; j < x && !q.empty(); j++) {
			q.pop();
		}
	}
	return wait <= D;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N >> D >> M;
	for (int i = 1; i <= M; i++) {
		int t;
		cin >> t;
		arr[t].push_back(i);
	}
	int high = M;
	int low = 0;
	while (low < high) {
		int mid = (high+low+1)/2;
		if (check(mid)) {
			high = mid-1;
		}
		else {
			low = mid;
		}
	}
	int ans = high+1;
	cout << ans << "\n";
	queue<int> q;
	for (int i = 1; i <= N; i++) {
		for (auto v: arr[i]) {
			q.push(v);
		}
		for (int j = 0; j < ans && !q.empty(); j++) {
			cout << q.front() << ' ';
			q.pop();
		}
		cout << 0 << '\n';
	}	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 4004 KB Output is correct
2 Correct 23 ms 4004 KB Output is correct
3 Correct 23 ms 3988 KB Output is correct
4 Correct 22 ms 3996 KB Output is correct
5 Correct 23 ms 4004 KB Output is correct
6 Correct 22 ms 4044 KB Output is correct
7 Correct 22 ms 3996 KB Output is correct
8 Correct 24 ms 4000 KB Output is correct
9 Correct 38 ms 4152 KB Output is correct
10 Correct 35 ms 4172 KB Output is correct
11 Correct 24 ms 3760 KB Output is correct
12 Correct 48 ms 4988 KB Output is correct
13 Correct 68 ms 6808 KB Output is correct
14 Correct 103 ms 8276 KB Output is correct
15 Correct 113 ms 9040 KB Output is correct
16 Correct 150 ms 11040 KB Output is correct
17 Correct 190 ms 13060 KB Output is correct
18 Correct 187 ms 12748 KB Output is correct
19 Correct 209 ms 13504 KB Output is correct
20 Correct 176 ms 12996 KB Output is correct