답안 #936925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936925 2024-03-03T03:52:22 Z ventusliberum Job Scheduling (CEOI12_jobs) C++17
100 / 100
115 ms 20624 KB
/**
 *    title:  Job Scheduling
**/
#include <bits/stdc++.h>
using namespace std;

template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { auto sep = ""; for (auto &x : v) os << exchange(sep, " ") << x; return os; }
template <class T> vector<T> &operator+=(vector<T> &v, const T &a) { for (auto &x : v) x += a; return v; }
template <class T> vector<T> &operator-=(vector<T> &v, const T &a) { for (auto &x : v) x -= a; return v; }
template <class T, class U> inline bool chmax(T &a, const U &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return (b < a ? a = b, 1 : 0); }
#define si(x) int(x.size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
using ll = long long;
constexpr int inf = 1001001001;
constexpr long long infll = 4004004004004004004LL;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, D, M;
  cin >> N >> D >> M;
  vector<vector<int>> cn(N+1);
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    cn[x].push_back(i);
  }
  int l = 0, r = M + 1;
  auto valid = [&](int x) {
    int sum = 0;
    for (int i = 1; i <= N; i++) {
      if (si(cn[i])) {
        sum += si(cn[i]);
        if ((sum + x - 1) / x > D + 1) return false;
      }
      sum = max(0, sum - x);
    }
    return true;
  };
  while (l < r) {
    int mid = (l + r) / 2;
    valid(mid) ? r = mid : l = mid + 1;
  }

  cout << l << '\n';
  vector<int> use;
  int j = 0;
  for (int i = 1; i <= N; i++) {
    for (int x : cn[i]) {
      use.push_back(x);
    }
    vector<int> cur;
    for (int s = j; j < min(si(use), s + l); j++) {
      cur.push_back(use[j]);
    }
    cur += 1;
    cout << cur;
    if (si(cur)) cout << ' ';
    cout << 0 << '\n';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 2588 KB Output is correct
2 Correct 12 ms 2788 KB Output is correct
3 Correct 12 ms 2588 KB Output is correct
4 Correct 12 ms 2588 KB Output is correct
5 Correct 12 ms 2588 KB Output is correct
6 Correct 13 ms 2588 KB Output is correct
7 Correct 14 ms 2588 KB Output is correct
8 Correct 13 ms 2584 KB Output is correct
9 Correct 18 ms 4820 KB Output is correct
10 Correct 18 ms 4952 KB Output is correct
11 Correct 16 ms 2516 KB Output is correct
12 Correct 23 ms 4296 KB Output is correct
13 Correct 39 ms 7632 KB Output is correct
14 Correct 65 ms 9420 KB Output is correct
15 Correct 58 ms 11172 KB Output is correct
16 Correct 91 ms 15840 KB Output is correct
17 Correct 106 ms 17280 KB Output is correct
18 Correct 92 ms 16848 KB Output is correct
19 Correct 115 ms 20624 KB Output is correct
20 Correct 99 ms 17868 KB Output is correct