제출 #666717

#제출 시각아이디문제언어결과실행 시간메모리
666717omikron123Job Scheduling (CEOI12_jobs)C++14
90 / 100
1085 ms14028 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; } bool cmp(J &a, J &b) {return a.s < b.s;} int main() { scanf("%d %d %d", &n, &d, &m); for (int i = 0; i < m; i++) { scanf("%d", &jobs[i].s); 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 */

컴파일 시 표준 에러 (stderr) 메시지

jobs.cpp: In function 'int main()':
jobs.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d %d %d", &n, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%d", &jobs[i].s);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...