Submission #623171

# Submission time Handle Problem Language Result Execution time Memory
623171 2022-08-05T09:31:11 Z EthanKim8683 Job Scheduling (CEOI12_jobs) C++17
100 / 100
153 ms 20428 KB
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>

using namespace std;

using I = int;
using B = bool;

const I N = 100000;
const I M = 1000000;

I days[M];
vector<I> reqs[N];
queue<I> que;
I n, m, d;

B tes(I cnt) {
  I siz = 0;
  for (I i = 0; i < n; i++) {
    if (!reqs[i].empty()) {
      siz += reqs[i].size() - 1;
      if (siz / cnt > d)
        return false;
      siz++;
    }
    siz -= min(siz, cnt);
  }
  if (siz > 0)
    return false;
  return true;
}

I main(void) {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> d >> m;
  for (I i = 0; i < m; i++)
    cin >> days[i];
  for (I i = 0; i < m; i++)
    reqs[days[i] - 1].push_back(i + 1);
  I l = 1;
  I r = m;
  while (l < r) {
    const I m = l + (r - l) / 2;
    if (tes(m))
      r = m;
    else
      l = m + 1;
  }
  printf("%i\n", l);
  for (I i = 0; i < n; i++) {
    for (const auto req : reqs[i])
      que.push(req);
    for (I j = 0; j < l && !que.empty(); j++) {
      printf("%i ", que.front());
      que.pop();
    }
    printf("0\n");
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 4744 KB Output is correct
2 Correct 16 ms 4776 KB Output is correct
3 Correct 16 ms 4692 KB Output is correct
4 Correct 15 ms 4796 KB Output is correct
5 Correct 20 ms 4716 KB Output is correct
6 Correct 16 ms 4744 KB Output is correct
7 Correct 16 ms 4748 KB Output is correct
8 Correct 17 ms 4692 KB Output is correct
9 Correct 20 ms 4684 KB Output is correct
10 Correct 20 ms 4668 KB Output is correct
11 Correct 17 ms 4564 KB Output is correct
12 Correct 32 ms 6568 KB Output is correct
13 Correct 52 ms 9140 KB Output is correct
14 Correct 71 ms 11592 KB Output is correct
15 Correct 83 ms 12912 KB Output is correct
16 Correct 104 ms 16012 KB Output is correct
17 Correct 126 ms 18724 KB Output is correct
18 Correct 119 ms 18756 KB Output is correct
19 Correct 153 ms 20428 KB Output is correct
20 Correct 142 ms 18708 KB Output is correct