# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
674276 | thienbao1602 | Job Scheduling (CEOI12_jobs) | C++17 | 504 ms | 59576 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 ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<ll>
using namespace std;
const int N = 1e5 + 55;
int days, delay, number_jobs;
vector<pair<ll, ll>> jobs;
vector<vi> ans;
pair<bool, vector<vi>> check(const vector<pair<ll, ll>> jobs, ll machine)
{
vector<vi> schedule(days);
ll id_job = 0;
for(int i=0; i<days; i++)
{
for(int cur_machine=0; cur_machine<machine; cur_machine++)
{
if (jobs[id_job].fi > i + 1) break;
if (jobs[id_job].fi + delay >= i + 1)
{
schedule[i].pb(jobs[id_job++].se);
} else return make_pair(false, schedule);
if (id_job == number_jobs) return make_pair(true, schedule);
}
}
return make_pair(false, schedule);
}
ll bs(ll l, ll r)
{
while(l < r)
{
ll m = (l + r) >> 1;
pair<bool, vector<vi>> curResult = check(jobs, m);
if (curResult.fi)
{
r = m;
ans = curResult.se;
} else
{
l = m + 1;
}
}
return l;
}
void solve()
{
cin >> days >> delay >> number_jobs;
for(int i=0; i<number_jobs; i++)
{
ll x;
cin >> x;
jobs.pb({x, i + 1});
}
sort(jobs.begin(), jobs.end());
cout << bs(1, days) << "\n";
for(int i=0; i<days; i++)
{
for(auto x : ans[i])
{
cout << x << " ";
}
cout << "0\n";
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |