# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
694189 | vjudge1 | Job Scheduling (CEOI12_jobs) | C++17 | 213 ms | 44492 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;
#define pb push_back
#define all(s) s.begin(), s.end()
#ifndef LOCALDEBUG
#define LOCALDEBUG false
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int n, d, m;
vi requestsOnDay[(int)1e6 + 1];
int jobs[(int)1e6 + 1];
bool check(int machines)
{
queue<int> active;
for (int i = 1; i <= n; i++)
{
// get new requests
for (int id : requestsOnDay[i])
active.push(id);
int mm = machines;
while (!active.empty() && mm--)
{
int cur = active.front();
if (jobs[cur] + d < i)
return false;
else
active.pop();
}
}
return active.size() == 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> d >> m;
for (int i = 0; i < m; i++)
{
int x;
cin >> x;
jobs[i] = x;
requestsOnDay[x].pb(i);
}
int lo = 1, hi = 1e6;
while (lo < hi)
{
int mid = (lo + hi) / 2;
if (check(mid))
hi = mid - 1;
else
lo = mid + 1;
}
cout << lo << '\n';
vvi onDay(n + 1);
queue<int> active;
for (int i = 1; i <= n; i++)
{
// get new requests
for (int id : requestsOnDay[i])
active.push(id);
int mm = lo;
while (!active.empty() && mm--)
{
int cur = active.front();
onDay[i].pb(cur);
active.pop();
}
}
for (int i = 0; i < n; i++)
{
for (int id : onDay[i + 1])
cout << id + 1 << " ";
cout << "0\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |