Submission #709906

#TimeUsernameProblemLanguageResultExecution timeMemory
709906groshiJob Scheduling (CEOI12_jobs)C++17
100 / 100
357 ms17208 KiB
#include<iostream> #include<vector> #include<algorithm> #include<queue> using namespace std; vector<pair<int,int> > Q; int n,d,m; void wypisz(int x) { cout<<x<<"\n"; queue<pair<int,int> > kolejka; bool git=1; int gdzie=0; for(int i=1;i<=n;i++) { while(gdzie<Q.size() && Q[gdzie].first==i) { kolejka.push(Q[gdzie]); gdzie++; } for(int j=1;j<=x;j++) { if(kolejka.size()==0) break; int kiedy=kolejka.front().first; cout<<kolejka.front().second<<" "; kolejka.pop(); } cout<<"0\n"; } } bool git(int x) { queue<pair<int,int> > kolejka; bool git=1; int gdzie=0; for(int i=1;i<=n;i++) { while(gdzie<Q.size() && Q[gdzie].first==i) { kolejka.push(Q[gdzie]); gdzie++; } for(int j=1;j<=x;j++) { if(kolejka.size()==0) break; int kiedy=kolejka.front().first; if(kiedy+d<i) { git=0; break; } kolejka.pop(); } if(git==0) break; } if(git && kolejka.size()==0) return 1; else return 0; } int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int x; cin>>n>>d>>m; for(int i=1;i<=m;i++) { cin>>x; Q.push_back({x,i}); } sort(Q.begin(),Q.end()); int pocz=1,kon=m+1,sre,ostd; while(pocz<kon) { sre=(pocz+kon)/2; if(git(sre)) { ostd=sre; kon=sre; } else pocz=sre+1; } wypisz(ostd); return 0; }

Compilation message (stderr)

jobs.cpp: In function 'void wypisz(int)':
jobs.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         while(gdzie<Q.size() && Q[gdzie].first==i)
      |               ~~~~~^~~~~~~~~
jobs.cpp:25:17: warning: unused variable 'kiedy' [-Wunused-variable]
   25 |             int kiedy=kolejka.front().first;
      |                 ^~~~~
jobs.cpp:12:10: warning: unused variable 'git' [-Wunused-variable]
   12 |     bool git=1;
      |          ^~~
jobs.cpp: In function 'bool git(int)':
jobs.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         while(gdzie<Q.size() && Q[gdzie].first==i)
      |               ~~~~~^~~~~~~~~
jobs.cpp: In function 'int32_t main()':
jobs.cpp:87:11: warning: 'ostd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   87 |     wypisz(ostd);
      |     ~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...