Submission #666722

#TimeUsernameProblemLanguageResultExecution timeMemory
666722omikron123Job Scheduling (CEOI12_jobs)C++14
90 / 100
1090 ms10736 KiB
// https://oj.uz/problem/view/CEOI12_jobs #include <cstdio> #include <algorithm> #include <queue> #include <vector> using namespace std; // n,d<=1e5, m<=1e6 int n, d, m; struct J { int s, idx; }; J jobs[1000005]; // return if x machine is enough bool check(int x, bool print) { // {deadline, idx} priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > q; int j = 0; // job index for (int i = 1; i <= n; i++) { // enqueue job arrivals for (; j < m && jobs[j].s == i; j++) q.push({i + d, jobs[j].idx}); // consume jobs in queue int cnt = 0; while(!q.empty() && cnt < x) { int deadline = q.top().first; int idx = q.top().second; q.pop(); if (deadline < i) // already expired return false; cnt++; if (print) printf("%d ", idx); } if (print) printf("0\n"); } return true; } inline bool cmp(J &a, J &b) {return a.s < b.s;} inline int read() { int r = 0; bool start = false, neg = false; while (true) { char c = getchar(); if (!start && c != '-' && (c < '0' || c > '9')) continue; start = true; if (c == '-') neg = true; else if (c >= '0' && c <= '9') r = r * 10 + c - '0'; else break; } return r; } int main() { scanf("%d %d %d", &n, &d, &m); for (int i = 0; i < m; i++) { jobs[i].s = read(); jobs[i].idx = i+1; } sort(jobs, jobs+m, cmp); int low = 1, high = m; while (low < high) { int mid = (low + high) / 2; if (check(mid, false)) high = mid; else low = mid+1; } printf("%d\n", low); check(low, true); return 0; } /* 8 2 12 1 2 4 2 1 3 5 6 2 3 6 4 answer is 2 */

Compilation message (stderr)

jobs.cpp: In function 'int read()':
jobs.cpp:50:25: warning: variable 'neg' set but not used [-Wunused-but-set-variable]
   50 |     bool start = false, neg = false;
      |                         ^~~
jobs.cpp: In function 'int main()':
jobs.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     scanf("%d %d %d", &n, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...