Submission #102159

#TimeUsernameProblemLanguageResultExecution timeMemory
102159thebesJob Scheduling (CEOI12_jobs)C++14
100 / 100
476 ms16760 KiB
#include <bits/stdc++.h> using namespace std; const int MN = 1e5+5; int N, D, M, i, x, lo, hi, src[10*MN]; vector<int> adj[MN]; queue<int> q; bool check(int m){ while(q.size()) q.pop(); for(int i=1;i<=N;i++){ for(auto v : adj[i]) q.push(v); int sz = min((int)q.size(), m); while(sz--){ if(src[q.front()]+D<i) return 0; q.pop(); } } return q.size()==0; } int main(){ for(scanf("%d%d%d",&N,&D,&M),i=1;i<=M;i++) scanf("%d",&x), adj[x].push_back(i), src[i]=x; lo = 1, hi = M; while(lo<hi){ int m = lo+hi>>1; if(check(m)) hi=m; else lo=m+1; } printf("%d\n",lo); while(q.size()) q.pop(); for(i=1;i<=N;i++){ for(auto v: adj[i]) q.push(v); int sz = min((int)q.size(), lo); while(sz--){ printf("%d ",q.front()); q.pop(); } printf("0\n"); } return 0; }

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:27:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = lo+hi>>1;
                 ~~^~~
jobs.cpp:23:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d%d%d",&N,&D,&M),i=1;i<=M;i++)
         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
jobs.cpp:24:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x), adj[x].push_back(i), src[i]=x;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...