# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112868 | 2019-05-22T10:54:12 Z | Hassoony | Job Scheduling (CEOI12_jobs) | C++17 | 662 ms | 34344 KB |
#include <bits/stdc++.h> using namespace std; const int MX=1e5+9; int n,m,d,a[MX],b[MX]; bool check(int mach){ for(int i=1;i<=n;i++)a[i]=b[i]; multiset<int>ms; int last=0; for(int i=1;i<=2*n;i++){ mach+=last; last=0; while(mach&&!ms.empty()){ if(*ms.begin()<i)return 0; ms.erase(ms.begin()); mach--; last++; } while(mach&&a[i]){ mach--; a[i]--; last++; } while(a[i]){ ms.insert(i+d); a[i]--; } } return 1; } int bn(int l,int r){ int ans=m; while(l<=r){ int mid=(l+r)/2; if(check(mid)){ r=mid-1; ans=mid; } else l=mid+1; } return ans; } vector<int>v[MX],v1[MX]; void fix(int mach){ for(int i=1;i<=n;i++)a[i]=b[i]; multiset<pair<int,int> >ms; int last=0; for(int i=1;i<=2*n;i++){ mach+=last; last=0; while(mach&&!ms.empty()){ v[i].push_back(ms.begin()->second); ms.erase(ms.begin()); mach--; last++; } while(mach&&v1[i].size()){ mach--; v[i].push_back(v1[i].back()); v1[i].pop_back(); last++; } while(v1[i].size()){ ms.insert({i+d,v1[i].back()}); v1[i].pop_back(); } } for(int i=1;i<=n;i++){ for(auto pp:v[i]){ cout<<pp<<" "; } puts("0"); } } int main(){ cin>>n>>d>>m; for(int i=1;i<=m;i++){ int x; scanf("%d",&x); a[x]++; v1[x].push_back(i); } for(int i=1;i<=n;i++)b[i]=a[i]; // check(1); int ans=bn(1,m); cout<<ans<<endl; fix(ans); } /* 8 2 12 1 2 4 2 1 3 5 6 2 3 6 4 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 156 ms | 9292 KB | Output is correct |
2 | Correct | 155 ms | 9300 KB | Output is correct |
3 | Correct | 156 ms | 9484 KB | Output is correct |
4 | Correct | 154 ms | 9456 KB | Output is correct |
5 | Correct | 156 ms | 9452 KB | Output is correct |
6 | Correct | 154 ms | 9460 KB | Output is correct |
7 | Correct | 155 ms | 9328 KB | Output is correct |
8 | Correct | 156 ms | 9380 KB | Output is correct |
9 | Incorrect | 30 ms | 8952 KB | Output isn't correct |
10 | Incorrect | 29 ms | 8960 KB | Output isn't correct |
11 | Correct | 49 ms | 7032 KB | Output is correct |
12 | Correct | 204 ms | 9900 KB | Output is correct |
13 | Correct | 198 ms | 12280 KB | Output is correct |
14 | Correct | 335 ms | 16504 KB | Output is correct |
15 | Correct | 147 ms | 15096 KB | Output is correct |
16 | Correct | 216 ms | 18352 KB | Output is correct |
17 | Correct | 390 ms | 23416 KB | Output is correct |
18 | Correct | 662 ms | 22264 KB | Output is correct |
19 | Runtime error | 236 ms | 34344 KB | Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
20 | Correct | 393 ms | 23416 KB | Output is correct |