# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384205 | kaplanbar | Job Scheduling (CEOI12_jobs) | C++17 | 1096 ms | 13548 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;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, d, m;
cin >> n >> d >> m;
vector<vector<int>> use(n);
for(int i = 0; i < m; i++) {
int x;
cin >> x;
use[x - 1].push_back(i);
}
auto check = [&](int co) -> vector<vector<int>> {
vector<vector<int>> ans(n);
queue<pair<int,int>> closest;
for(int i = 0; i < n; i++) {
ans[i].clear();
for(int x : use[i]) {
closest.push({i + d, x});
}
if(!closest.empty() && closest.front().first < i) return vector<vector<int>>{};
for(int j = 0; j < co; j++) {
if(!closest.empty()) {
ans[i].push_back(closest.front().second);
closest.pop();
}
}
}
if(!closest.empty()) return vector<vector<int>>{};
return ans;
};
int l = 0, r = m;
while(l + 1 < r) {
int mid = (l + r) / 2;
if(!check(mid).empty()) r = mid;
else l = mid;
}
cout << r << "\n";
auto ans = check(r);
for(int i = 0; i < n; i++) {
for(int x : ans[i]) cout << x + 1 << " ";
cout << 0 << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |