# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
642591 | accidentac | Job Scheduling (CEOI12_jobs) | C++17 | 375 ms | 23232 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, d, m;
vector<array<int, 2>> jobs;
// return true if can use count no. of machines to handle all jobs
bool ok(int count) {
queue<int> q;
for (int i = 1, j = 0; i <= n; i++) {
while (j < m && jobs[j][0] == i) {
q.push(j++);
}
if (q.size() && i - jobs[q.front()][0] > d) return false;
for (int rep = 0; rep < count && !q.empty(); rep++) {
q.pop();
}
}
return true;
}
vector<vector<int>> form(int count) {
vector<vector<int>> ans(n);
queue<int> q;
for (int i = 1, j = 0; i <= n; i++) {
vector<int> cur;
while (j < m && jobs[j][0] == i) {
q.push(j++);
}
for (int rep = 0; rep < count && !q.empty(); rep++) {
ans[i - 1].push_back(jobs[q.front()][1]);
q.pop();
}
ans[i - 1].push_back(0);
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> d >> m;
jobs = vector<array<int, 2>>(m);
for (int i = 0; i < m; i++) {
cin >> jobs[i][0];
jobs[i][1] = i + 1;
}
sort(jobs.begin(), jobs.end());
int lo = 1, hi = m, ans = m;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if (ok(mid)) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans << '\n';
for (auto row : form(ans)) {
for (int x : row) {
cout << x;
if (x != 0) cout << ' ';
}
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |