답안 #893744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893744 2023-12-27T10:44:44 Z MilosMilutinovic Cookies (JOI23_cookies) C++14
0 / 100
1000 ms 596 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int m;
  cin >> m;
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  sort(b.begin(), b.end());
  int sa = accumulate(a.begin(), a.end(), 0);
  const int inf = (int) 1e9;
  vector<int> dp(sa + 1, inf);
  dp[0] = 0;
  vector<int> to(sa + 1);
  for (int r = 0; r < m; r++) {
    for (int i = 0; i < sa; i++) {
      if (dp[i] == inf) {
        continue;
      }
      int left = 0;
      {
        int cur = i;
        vector<int> f;
        while (cur > 0) {
          f.push_back(cur - to[cur]);
          cur = to[cur];
        }
        reverse(f.begin(), f.end());
        set<pair<int, int>> all;
        for (int j = 0; j < n; j++) {
          all.emplace(a[j], j);
        }
        for (int x : f) {
          vector<pair<int, int>> to_add;
          for (int iter = 0; iter < x; iter++) {
            assert(!all.empty());
            auto it = prev(all.end());
            int idx = it->second;
            int val = it->first;
            all.erase(it);
            if (val > 1) {
              to_add.emplace_back(val - 1, idx);
            }
          }
          for (auto& p : to_add) {
            all.insert(p);
          }
        }
        left = (int) all.size();
      }
      if (left >= b[r] && i + b[r] <= sa && dp[i + b[r]] > dp[i] + 1) {
        dp[i + b[r]] = dp[i] + 1;
        to[i + b[r]] = i;
      }
    }
  }
  if (dp[sa] == inf) {
    cout << -1 << '\n';
    return 0;
  }
  vector<int> f;
  int p = sa;
  while (p > 0) {
    f.push_back(p - to[p]);
    p = to[p];
  }
  reverse(f.begin(), f.end());
  vector<vector<int>> res;
  multiset<pair<int, int>> all;
  for (int i = 0; i < n; i++) {
    all.emplace(a[i], i);
  }
  for (int x : f) {
    res.push_back({});
    vector<int> ids;
    for (int i = 0; i < x; i++) {
      assert(!all.empty());
      auto it = prev(all.end());
      res.back().push_back(it->second);
      ids.push_back(it->second);
      all.erase(it);
    }
    for (int i : ids) {
      a[i] -= 1;
      if (a[i] > 0) {
        all.emplace(a[i], i);
      }
    }
  }
  cout << (int) res.size() << '\n';
  for (auto& p : res) {
    cout << (int) p.size() << " ";
    for (int i = 0; i < (int) p.size(); i++) {
      cout << p[i] + 1 << " ";
    }
    cout << '\n';
  }
  cout << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 16 ms 484 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Execution timed out 1090 ms 372 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 16 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 7 ms 348 KB Output is correct
9 Correct 224 ms 596 KB Output is correct
10 Execution timed out 1073 ms 572 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Incorrect 0 ms 344 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 16 ms 484 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Execution timed out 1090 ms 372 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 16 ms 484 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Execution timed out 1090 ms 372 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 16 ms 484 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Execution timed out 1090 ms 372 KB Time limit exceeded
11 Halted 0 ms 0 KB -