제출 #1280337

#제출 시각아이디문제언어결과실행 시간메모리
1280337ducanh0811Job Scheduling (CEOI12_jobs)C++20
100 / 100
98 ms25724 KiB
#include <bits/stdc++.h> #define int long long #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define REV(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) using namespace std; #define MAXN 100005 int n, d, m; vector<int> task[MAXN]; vector<int> res[MAXN]; bool g(int x){ deque<pair<int, int>> dq; FOR(i, 1, n){ if (task[i].size()) dq.push_back(make_pair(i + d, task[i].size())); int take = x; while (take > 0 && dq.size()) { pair<int, int> tmp = dq.front(); dq.pop_front(); if (take >= tmp.second) { take -= tmp.second; } else { tmp.second -= take; take = 0; dq.push_front(tmp); } } if (dq.size() && dq.front().first <= i) return false; } return true; } void solve(){ cin >> n >> d >> m; FOR(i, 1, m){ int x; cin >> x; task[x].push_back(i); } int lo = 1, hi = m, ans = hi; while (lo <= hi){ int mid = (lo + hi) >> 1; if (g(mid)){ ans = mid; hi = mid - 1; } else lo = mid + 1; } cout << ans << '\n'; deque<int> process; FOR(i, 1, n){ for (int &x : task[i]) process.push_back(x); int take = ans; while (take > 0 && process.size()){ take--; res[i].push_back(process.front()); process.pop_front(); } } FOR(i, 1, n){ for (int &x : res[i]) cout << x << ' '; cout << "0\n"; } } /** 8 2 12 1 2 4 2 1 3 5 6 2 3 6 4 6 3 6 1 1 1 1 1 1 **/ int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...