답안 #893730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893730 2023-12-27T10:33:15 Z MilosMilutinovic Cookies (JOI23_cookies) C++14
6 / 100
1000 ms 728 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];
  }
  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 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();
    }
    for (int j = 0; j < m; j++) {
      if (left >= b[j] && i + b[j] <= sa && dp[i + b[j]] >= dp[i] + 1) {
        dp[i + b[j]] = dp[i] + 1;
        to[i + b[j]] = 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 16 ms 488 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 13 ms 348 KB Output is correct
11 Correct 7 ms 492 KB Output is correct
12 Correct 15 ms 348 KB Output is correct
13 Correct 10 ms 348 KB Output is correct
14 Correct 7 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 7 ms 348 KB Output is correct
17 Correct 14 ms 348 KB Output is correct
18 Correct 15 ms 348 KB Output is correct
19 Correct 10 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 12 ms 480 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 9 ms 488 KB Output is correct
24 Correct 13 ms 348 KB Output is correct
25 Correct 15 ms 484 KB Output is correct
26 Correct 10 ms 348 KB Output is correct
27 Correct 9 ms 348 KB Output is correct
28 Correct 10 ms 480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 17 ms 496 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 456 KB Output is correct
9 Correct 247 ms 728 KB Output is correct
10 Execution timed out 1048 ms 580 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 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 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 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 1 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 16 ms 488 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 13 ms 348 KB Output is correct
11 Correct 7 ms 492 KB Output is correct
12 Correct 15 ms 348 KB Output is correct
13 Correct 10 ms 348 KB Output is correct
14 Correct 7 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 7 ms 348 KB Output is correct
17 Correct 14 ms 348 KB Output is correct
18 Correct 15 ms 348 KB Output is correct
19 Correct 10 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 12 ms 480 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 9 ms 488 KB Output is correct
24 Correct 13 ms 348 KB Output is correct
25 Correct 15 ms 484 KB Output is correct
26 Correct 10 ms 348 KB Output is correct
27 Correct 9 ms 348 KB Output is correct
28 Correct 10 ms 480 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 600 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Incorrect 0 ms 348 KB Output isn't correct
47 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 1 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 16 ms 488 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 13 ms 348 KB Output is correct
11 Correct 7 ms 492 KB Output is correct
12 Correct 15 ms 348 KB Output is correct
13 Correct 10 ms 348 KB Output is correct
14 Correct 7 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 7 ms 348 KB Output is correct
17 Correct 14 ms 348 KB Output is correct
18 Correct 15 ms 348 KB Output is correct
19 Correct 10 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 12 ms 480 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 9 ms 488 KB Output is correct
24 Correct 13 ms 348 KB Output is correct
25 Correct 15 ms 484 KB Output is correct
26 Correct 10 ms 348 KB Output is correct
27 Correct 9 ms 348 KB Output is correct
28 Correct 10 ms 480 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 600 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Incorrect 0 ms 348 KB Output isn't correct
47 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 1 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 16 ms 488 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 13 ms 348 KB Output is correct
11 Correct 7 ms 492 KB Output is correct
12 Correct 15 ms 348 KB Output is correct
13 Correct 10 ms 348 KB Output is correct
14 Correct 7 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 7 ms 348 KB Output is correct
17 Correct 14 ms 348 KB Output is correct
18 Correct 15 ms 348 KB Output is correct
19 Correct 10 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 12 ms 480 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 9 ms 488 KB Output is correct
24 Correct 13 ms 348 KB Output is correct
25 Correct 15 ms 484 KB Output is correct
26 Correct 10 ms 348 KB Output is correct
27 Correct 9 ms 348 KB Output is correct
28 Correct 10 ms 480 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 17 ms 496 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 456 KB Output is correct
37 Correct 247 ms 728 KB Output is correct
38 Execution timed out 1048 ms 580 KB Time limit exceeded
39 Halted 0 ms 0 KB -