# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
679818 | peijar | Job Scheduling (CEOI12_jobs) | C++17 | 408 ms | 32852 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>
#define int long long
using namespace std;
namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
out << "[";
for (int i = 0; i < (int)vec.size(); ++i) {
out << vec[i];
if (i + 1 < (int)vec.size())
out << ", ";
}
return out << "]";
}
} // namespace std
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << H;
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int nbJours, nbTravaux, deadline;
cin >> nbJours >> deadline >> nbTravaux;
vector<int> debut(nbTravaux);
for (int &x : debut) {
cin >> x;
--x;
}
vector<int> order(nbTravaux);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(),
[&](int i, int j) { return debut[i] < debut[j]; });
auto check = [&](int nbMachines) -> bool {
queue<int> dispo;
for (int i = 0; i < nbJours; ++i)
dispo.push(i);
vector<int> surTemps(nbJours);
for (int i : order) {
int t = debut[i];
while (!dispo.empty() and dispo.front() < t)
dispo.pop();
if (dispo.empty() or dispo.front() > t + deadline)
return false;
int tt = dispo.front();
if (tt > t + deadline)
return false;
surTemps[tt]++;
if (surTemps[tt] == nbMachines)
dispo.pop();
}
return true;
};
int lo = 1, up = nbTravaux;
while (lo < up) {
int mid = (lo + up) / 2;
if (check(mid))
up = mid;
else
lo = mid + 1;
}
cout << lo << endl;
vector<vector<int>> onDay(nbJours);
queue<int> dispo;
for (int i = 0; i < nbJours; ++i)
dispo.push(i);
vector<int> surTemps(nbJours);
for (int i : order) {
int t = debut[i];
while (!dispo.empty() and dispo.front() < t)
dispo.pop();
if (dispo.empty() or dispo.front() > t + deadline)
assert(false);
int tt = dispo.front();
if (tt > t + deadline)
assert(false);
surTemps[tt]++;
onDay[tt].push_back(i + 1);
if (surTemps[tt] == lo)
dispo.pop();
}
for (int i = 0; i < nbJours; ++i) {
for (int x : onDay[i])
cout << x << ' ';
cout << 0 << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |