제출 #674283

#제출 시각아이디문제언어결과실행 시간메모리
674283thienbao1602Job Scheduling (CEOI12_jobs)C++17
40 / 100
402 ms45464 KiB
#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=1; i<=days; i++) { for(int cur_machine=0; cur_machine<machine; cur_machine++) { if (jobs[id_job].fi > i) break; if (jobs[id_job].fi + delay >= i) { schedule[i - 1].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; vector<pair<ll, ll>> jobs(number_jobs); for(int i=0; i<number_jobs; i++) { ll x; cin >> x; jobs[i] = make_pair(x, i + 1); } sort(jobs.begin(), jobs.end()); ll l = 1, r = days; 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; } } cout << l << "\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 timeMemoryGrader output
Fetching results...