Submission #1153912

#TimeUsernameProblemLanguageResultExecution timeMemory
1153912zhasynJob Scheduling (CEOI12_jobs)C++20
58 / 100
321 ms22792 KiB
//#include "gondola.h" #include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 1e6 + 100, M = 1e7 + 10, len = 21, inf = 1e18; const ll mod = 1000000009LL; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll um(ll a, ll b){ return (1LL * a * b) % mod; } ll subr(ll a, ll b){ return ((1LL * a - b) % mod + mod) % mod; } int n, d, from = 0, m; pii a[N]; vector <vector <int>> vec; bool check(int x){ int st = 1; for(int i = 1; i <= n; i++){ if((int)vec.size() - from > d) return 0; vector <int> cur; while(st <= m){ if(a[st].F == i){ cur.pb(a[st].S); st++; } else break; } vec.pb(cur); int xx = x; while(xx--){ while(from < (int)vec.size()){ if(vec[from].size() == 0) from++; else break; } if(from >= (int)vec.size()) break; vec[from].pop_back(); while(from < (int)vec.size()){ if(vec[from].size() == 0) from++; else break; } } } return true; } void make(int x){ int st = 1; for(int i = 1; i <= n; i++){ vector <int> cur; while(st <= m){ if(a[st].F == i){ cur.pb(a[st].S); st++; } else break; } vec.pb(cur); int xx = x; while(xx--){ while(from < (int)vec.size()){ if(vec[from].size() == 0) from++; else break; } if(from >= (int)vec.size()) break; cout << vec[from].back() << " "; vec[from].pop_back(); while(from < (int)vec.size()){ if(vec[from].size() == 0) from++; else break; } } cout << 0 << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> d >> m; for(int i = 1; i <= m; i++){ cin >> a[i].F; a[i].S = i; } sort(a + 1, a + 1 + m); int l = 0, r = m; while(r - l > 1){ int mid = (l + r) / 2; vec.clear(); from = 0; if(check(mid)) r = mid; else l = mid; } cout << r << endl; make(r); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...