Submission #1083832

#TimeUsernameProblemLanguageResultExecution timeMemory
1083832micro7Job Scheduling (CEOI12_jobs)C++17
100 / 100
145 ms13652 KiB
#include <algorithm> #include <cstdio> using namespace std; constexpr int MAXM = 1000000; int n, m, d; struct Job { int id, date; } jobs[MAXM]; bool check(int machines) { int l = 0, r = 0; for (int i = 1; i <= n; ++i) { while (r < m && jobs[r].date == i) ++r; if (l != r && l < m && jobs[l].date + d < i) return false; l = min(r, l + machines); } return l == r && r == m; } int first_true(int lo, int hi) { while (lo < hi) { int mid = lo + (hi - lo) / 2; if (check(mid)) { hi = mid; } else { lo = mid + 1; } } return lo; } void gen_schedule(int machines) { int l = 0, r = 0; for (int i = 1; i <= n; ++i) { putchar('\n'); while (r < m && jobs[r].date == i) ++r; int nl = min(r, l + machines); while (l < nl) { printf("%d ", jobs[l].id); ++l; } putchar('0'); } } int main() { scanf("%d%d%d", &n, &d, &m); for (int i = 0; i < m; ++i) { scanf("%d", &jobs[i].date); jobs[i].id = i + 1; } sort(jobs, jobs + m, [](const Job &l, const Job &r) { return l.date < r.date; }); int mn = first_true(1, m); printf("%d", mn); gen_schedule(mn); return 0; }

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:50:8: 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:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%d", &jobs[i].date);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...