Submission #484128

#TimeUsernameProblemLanguageResultExecution timeMemory
484128MilosMilutinovicJob Scheduling (CEOI12_jobs)C++14
100 / 100
207 ms17184 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=1010000; int n,d,m,a[N]; VI qs[N/10]; bool check(int x) { deque<int> dq; rep(i,1,n+1) { for (auto x:qs[i]) dq.pb(i+d); int len=min(SZ(dq),x); rep(j,0,len) if (dq[0]<i) return false; rep(j,0,len) dq.pop_front(); } return dq.empty(); } void rec(int x) { deque<int> dq; rep(i,1,n+1) { for (auto x:qs[i]) dq.pb(x); int len=min(SZ(dq),x); rep(j,0,len) { printf("%d ",dq[0]); dq.pop_front(); } printf("0\n"); } } int main() { scanf("%d%d%d",&n,&d,&m); rep(i,1,m+1) scanf("%d",a+i),qs[a[i]].pb(i); int l=1,r=m,ans=0; while (l<=r) { int md=(l+r)>>1; if (check(md)) ans=md,r=md-1; else l=md+1; } printf("%d\n",ans); rec(ans); } /* 8 2 12 1 2 4 2 1 3 5 6 2 3 6 4 */

Compilation message (stderr)

jobs.cpp: In function 'bool check(int)':
jobs.cpp:28:13: warning: unused variable 'x' [-Wunused-variable]
   28 |   for (auto x:qs[i]) dq.pb(i+d);
      |             ^
jobs.cpp: In function 'int main()':
jobs.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  scanf("%d%d%d",&n,&d,&m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
jobs.cpp:49:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |  rep(i,1,m+1) scanf("%d",a+i),qs[a[i]].pb(i);
      |               ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...