Submission #1011892

# Submission time Handle Problem Language Result Execution time Memory
1011892 2024-07-01T10:45:45 Z belgianbot Job Scheduling (CEOI12_jobs) C++14
100 / 100
169 ms 22040 KB
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> tasks;
int N, D, M;
vector<vector<int>> possible (int nbMachine) {
	queue <pair<int,int>> q;
	vector<vector<int>> ans(N);
	for (int i(0); i < N; i++) {
		if (!q.empty() && i - q.front().second > D) return {};
		int sum = nbMachine;
		for (int x : tasks[i]) q.push({x, i});
		while (!q.empty() && sum > 0) {
			sum--;
			ans[i].push_back(q.front().first);
			q.pop();
		}
	}
	if (!q.empty()) return {};
	return ans;
}
		
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> D >> M;
	tasks.resize(N);
	
	for (int i = 0; i < M; i++) {
		int a; cin >> a; a--;
		tasks[a].push_back(i + 1);
	}
	
	int l = 0, r = 1000000;
	while (l < r) {
		int mid = r - (r - l) / 2;
		//cout << l << " " << r << '\n';
		
		if (possible(mid).empty()) l = mid;
		else r = mid - 1;
	}
	
	cout << l + 1 << '\n';
	vector<vector<int>> ans = possible(l + 1);
	for (auto x : ans) {
		for (int y : x) {
			cout << y  << " ";
		}
		cout << "0\n";
	}
	
	return 0;
}
		
		
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3472 KB Output is correct
2 Correct 24 ms 3728 KB Output is correct
3 Correct 20 ms 3600 KB Output is correct
4 Correct 22 ms 3740 KB Output is correct
5 Correct 20 ms 3752 KB Output is correct
6 Correct 21 ms 3800 KB Output is correct
7 Correct 21 ms 3472 KB Output is correct
8 Correct 30 ms 3488 KB Output is correct
9 Correct 26 ms 7336 KB Output is correct
10 Correct 25 ms 7592 KB Output is correct
11 Correct 17 ms 2392 KB Output is correct
12 Correct 36 ms 4616 KB Output is correct
13 Correct 53 ms 7808 KB Output is correct
14 Correct 96 ms 10808 KB Output is correct
15 Correct 82 ms 10516 KB Output is correct
16 Correct 141 ms 14972 KB Output is correct
17 Correct 149 ms 18240 KB Output is correct
18 Correct 149 ms 16720 KB Output is correct
19 Correct 169 ms 22040 KB Output is correct
20 Correct 169 ms 18108 KB Output is correct