# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
927908 | megaminion | Job Scheduling (CEOI12_jobs) | C++17 | 1067 ms | 44648 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>
#include <ext/pb_ds/assoc_container.hpp>
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define pb push_back
#define ins insert
#define rsz resize
#define f first
#define s second
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
void setIO(string name = "")
{
cin.tie(0)->sync_with_stdio(0);
if (sz(name))
{
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
void prt(bool f)
{
// Unfortunatley, atcoder checker rejects YES/NO
cout<<((f)? "Yes\n" : "No\n");
}
using indexed_set = tree<int,null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>;
using ll = long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vb = vector<bool>;
using vs = vector<str>;
using mi = map<int, int>;
using ml = map<ll, ll>;
using si = set<int>;
using sl = set<ll>;
using sc = set<char>;
const ld PI = 2*acos(0.0);
const ld EPS = 1e-11;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const int inv2 = (MOD+1)/2;
const ll INF = 1e12;
const int M = 1e6;
const int N = 1e5;
#define int ll
int n, d, m;
int a[M], mp[N+1];
vector<int> v[N+1];
vector<int> p[N+1];
bool ok(int x, bool flag)
{
bool ret = true;
multiset<int> s;
for(int i = 1; i <= n; ++i)
{
v[i].clear();
for(int j = 0; j < mp[i]; ++j)
{
s.ins(i);
}
for(int j = 0; j < x; ++j)
{
if(s.empty()) break;
ret &= i - *s.begin() <= d;
if(flag)
{
v[i].pb(p[*s.begin()].back());
p[*s.begin()].pop_back();
}
s.erase(s.begin());
}
}
return ret;
}
void solve()
{
cin>>n>>d>>m;
for(int i = 0; i < m; ++i)
{
cin>>a[i];
mp[a[i]]++;
p[a[i]].pb(i+1);
}
int L = 1, R = 1e7, mid;
while(L < R)
{
mid = L + (R - L) / 2;
if(ok(mid, false))
{
R = mid;
}
else
{
L = mid+1;
}
}
cout<<L<<endl;
assert(ok(L, true));
for(int i = 1; i <= n; ++i)
{
for(int j = 0; j < sz(v[i]); ++j)
{
cout<<v[i][j];
if(j + 1 != sz(v[i])) cout<<" ";
else cout<<" 0";
}
if(v[i].empty())
{
cout<<"0";
}
if(i != n) cout<<endl;
}
}
int32_t main()
{
setIO();
int t = 1;
// cin>>t;
for(int i = 1; i <= t; ++i)
{
solve();
}
return 0;
}
/*
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |