# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
905034 | akliu | Job Scheduling (CEOI12_jobs) | C++11 | 1058 ms | 17256 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;
void fastio() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
void open(string filename) {
fastio();
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
typedef long long ll;
#define vll vector<ll>
#define vint vector<int>
#define vbool vector<bool>
#define vpii vector<pii>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ins(x) insert(x)
#define sz() size()
#define lb() lower_bound()
#define ub() upper_bound()
#define rsz resize
#define se second
#define fi first
#define cont continue
// scary demonic thing
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
struct g {
int day, n;
bool operator<(const g &y) {
if (day != y.day) return day < y.day;
return n < y.n;
}
};
int N, D, M;
vector<g> v;
bool check(int m) {
// Iterate to check if the minimum is valid
multiset<int> machines;
multiset<int> q;
int d = 0;
auto it = v.begin();
g val = *it;
while (d != N + 1) {
if (q.sz()) {
if (d - *(q.begin()) > D) {
return false;
}
}
machines.clear();
val = *it;
while (machines.sz() != m) {
if (!q.sz()) break;
machines.ins(*(q.begin()));
q.erase(q.begin());
}
while (val.day == d) {
if (machines.sz() != m) machines.ins(val.day);
else q.ins(val.day);
++it;
if (it == v.end()) break;
val = *it;
}
++d;
}
return true;
}
void solve() {
// Input
cin >> N >> D >> M;
for (int i = 0; i < M; ++i) {
int a; cin >> a;
v.pb({a, i + 1});
}
sort(v.begin(), v.end());
// Binary search
int l = 1, r = 1e6, m;
while (l < r) {
m = (l + r) / 2;
if (check(m)) r = m;
else l = m + 1;
}
cout << l << "\n";
// Iterate once more with the correct minimum
vector<vint> ans(N + 1);
multiset<pii> machines;
multiset<pii> q;
int d = 0;
auto it = v.begin();
g val = *it;
while (d != N + 1) {
machines.clear();
val = *it;
while (machines.sz() != l && q.sz()) {
pii valQ = *(q.begin());
machines.ins(mp(valQ.fi, valQ.se));
q.erase(q.begin());
}
while (val.day == d) {
val = *it;
if (machines.sz() != l) {
machines.ins(mp(val.day, val.n));
}
else q.ins(mp(val.day, val.n));
++it;
if (it == v.end()) break;
}
for (auto &x : machines) {
ans[d].pb(x.se);
}
++d;
}
// Output
for (int i = 1; i <= N; ++i) {
for (int j = 0; j < ans[i].sz(); ++j) {
cout << ans[i][j] << " ";
}
cout << "0\n";
}
}
int main() {
fastio();
int tc = 1;
// cin >> tc;
while (tc--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |