# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
448764 | 2021-08-01T12:31:30 Z | chuangsheep | Job Scheduling (CEOI12_jobs) | C++11 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) #define allr(x, r) begin(x), begin(x) + (r) #define mp make_pair using ll = long long; using pi = pair<int, int>; using vi = vector<int>; pair<bool, vector<vector<int>>> isFeasible(const vector<pi> &jobs, int N, int D, int machineCount) { set<pi> awaiting; vector<vi> plan(N); for (int i = 0, j = machineCount, d = 1; i < jobs.size(); i++) { if (d > N) return mp(false, plan); if (awaiting.size() != 0) { auto bg = awaiting.begin(); if (j == 0) { d++; j = machineCount; } if ((*bg).first + D >= d) { j--; plan.at(d - 1).push_back((*bg).second); awaiting.erase(bg); i--; continue; } else return mp(false, plan); } if (jobs.at(i).first > d) { d = jobs.at(i).first; j = machineCount - 1; plan.at(d - 1).push_back(jobs.at(i).second); } else { if (j == 0) { awaiting.insert(jobs.at(i)); while (i + 1 < jobs.size() && jobs.at(i + 1).first == jobs.at(i).first) awaiting.insert(jobs.at(++i)); } else { if (jobs.at(i).first + D >= d) { j--; plan.at(d - 1).push_back(jobs.at(i).second); } else return mp(false, plan); } } } return mp(d <= N, plan); } int main() { #if defined(DEBUG) && !defined(ONLINE_JUDGE) // DEBUG cerr << "DEBUG flag set - see test.out for output\n"; freopen("/home/chuang/shared-drives/F:/repos/cp/ois/ceoi12/test.in", "r", stdin); freopen("/home/chuang/shared-drives/F:/repos/cp/ois/ceoi12/test.out", "w", stdout); #else cin.tie(0)->sync_with_stdio(false); #endif int N, D, M; cin >> N >> D >> M; vector<pi> jobs(M); for (int i = 0; i < M; i++) { int day; cin >> day; jobs[i] = mp(day, i + 1); } sort(all(jobs)); int l = 1, r = M / D + 1; vector<vi> res; while (l < r) { int mid = (l + r) / 2; pair<bool, vector<vi>> cur = isFeasible(jobs, N, D, mid); if (cur.first) { r = mid; res = cur.second; } else l = mid + 1; } cout << l << "\n"; for (int i = 0; i < N; i++) { for (int &num : res[i]) { cout << num << " "; } cout << 0 << "\n"; } return 0; }