Submission #480509

#TimeUsernameProblemLanguageResultExecution timeMemory
480509imaginary_unitJob Scheduling (CEOI12_jobs)C++17
60 / 100
676 ms20060 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define fi first #define se second using namespace std; int n, d, m, temp; vector<vector<int> > a(100'000); bool ok(int mch) { priority_queue<int, vector<int>, greater<int> > pq; for(int i=1; i<=n; i++){ for(int j=0; j<a[i].size(); j++){ pq.push(i+d); } for(int j=0; j<mch; j++){ if(pq.empty()){ break; } if(pq.top() < i){ return 0; } pq.pop(); } } return 1; } int minMachines(int l, int r) { while(r-l>1){ int m=(l+r)/2; if(ok(m)){ r=m; } else{ l=m; } } return r; } int main() { //freopen("angry.in", "r", stdin); //freopen("angry.out", "w", stdout); scanf("%d %d %d", &n, &d, &m); for(int i=1; i<=m; i++){ scanf("%d", &temp); a[temp].push_back(i); } int ans=minMachines(1, n); cout << ans << '\n'; vector<vector<int> > tasks(n+1); priority_queue<pii, vector<pii>, greater<pii> > pq; for(int i=1; i<=n; i++){ for(int j=0; j<a[i].size(); j++){ pq.push({i+d, a[i][j]}); } for(int j=0; j<ans; j++){ if(pq.empty()){ break; } tasks[i].push_back(pq.top().se); pq.pop(); } } for(int i=1; i<=n; i++){ for(int j=0; j<tasks[i].size(); j++){ cout << tasks[i][j] << ' '; } cout << 0 << '\n'; } return 0; }

Compilation message (stderr)

jobs.cpp: In function 'bool ok(int)':
jobs.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for(int j=0; j<a[i].size(); j++){
      |                      ~^~~~~~~~~~~~
jobs.cpp: In function 'int main()':
jobs.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int j=0; j<a[i].size(); j++){
      |                      ~^~~~~~~~~~~~
jobs.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for(int j=0; j<tasks[i].size(); j++){
      |                      ~^~~~~~~~~~~~~~~~
jobs.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     scanf("%d %d %d", &n, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%d", &temp);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...