Submission #619760

#TimeUsernameProblemLanguageResultExecution timeMemory
619760gmsongJob Scheduling (CEOI12_jobs)C++11
100 / 100
506 ms27264 KiB
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <utility> 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 = 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:44:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |         while(h[head].size()>= s) head++;
      |               ~~~~~~~~~~~~~~^~~~
jobs.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (int j=0; j<h[i].size(); j++) {
      |                       ~^~~~~~~~~~~~
jobs.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d %d %d",&n,&d,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
jobs.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...