Submission #775463

#TimeUsernameProblemLanguageResultExecution timeMemory
775463kirakaminski968Job Scheduling (CEOI12_jobs)C++17
100 / 100
257 ms24072 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pi; vector<pi> p; int n,d,m; int a[1000005]; int v[100005]; vector<int> h[100005]; int f(int x){ memset(v,0,sizeof(v)); int head = 0; for (int i=0; i<m; i++) { head = max(head,p[i].first); while(v[head] >= x) head++; if(head > p[i].first + d) return 0; v[head]++; } return 1; } int main(){ scanf("%d %d %d",&n,&d,&m); for (int i=0; i<m; i++) { scanf("%d",&a[i]); p.push_back(pi(a[i],i+1)); } sort(p.begin(),p.end()); int s = 0, e = m; while (s != e) { int m = (s+e)/2; if(f(m)) e = m; else s = m+1; } printf("%d\n",s); int head = 0; for (int i=0; i<m; i++) { head = max(head,p[i].first); while(h[head].size()>= s) head++; if(head > p[i].first + d) return 0; h[head].push_back(p[i].second); } for (int i=1; i<=n; i++) { for (int j=0; j<h[i].size(); j++) { printf("%d ",h[i][j]); } puts("0"); } }

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:40:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |         while(h[head].size()>= s) head++;
      |               ~~~~~~~~~~~~~~^~~~
jobs.cpp:45:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for (int j=0; j<h[i].size(); j++) {
      |                       ~^~~~~~~~~~~~
jobs.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d %d %d",&n,&d,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
jobs.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...