Submission #1021162

# Submission time Handle Problem Language Result Execution time Memory
1021162 2024-07-12T15:00:07 Z erray Cookies (JOI23_cookies) C++17
13 / 100
85 ms 56488 KB
// author: erray
#include <bits/stdc++.h>

#ifdef DEBUG
  #include "debug.h"
#else
  #define debug(...) void(37)
#endif

using namespace std;

int main() {
  ios_base::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];
  }
  auto a = A;    
  sort(a.begin(), a.end());
  int M;
  cin >> M;
  vector<int> B(M);
  for (int i = 0; i < M; ++i) {
    cin >> B[M - i - 1];
  }
  constexpr int SUM = 15000 + 1;
  vector<int> allowed(SUM);
  allowed[0] = -1;
  {
    int64_t sum = 0;
    int p = 0;
    for (int i = 1; i < SUM; ++i) {
      while (p < N && a[p] < i) {
        sum += a[p];
        ++p;
      }
      allowed[i] = sum + (N - p) * i;
    }
  }
  using bs = bitset<SUM>;
  bs one = ~bs{};
  vector<bs> reach(SUM);
  reach[0][0] = true;
  for (auto add : B) { 
    for (int c = 1; c <= (SUM - 1) / add; ++c) {
      reach[c] |= reach[c - 1] << add;
      reach[c] &= one >> max(0, SUM - 1 - allowed[c]);
    } 
  }
  int size = 0;
  int sum = accumulate(a.begin(), a.end(), 0);
  while (size < SUM && !reach[size][sum]) ++size;
  if (size == SUM) {
    cout << -1 << '\n';
    return 0;
  }
  bs dec;
  for (auto x : B) {
    dec[SUM - x] = true;
  }
  vector<int> sizes;
  while (size > 0) {
    auto next = reach[size - 1] & (dec >> (SUM - sum));
    int next_sum = next._Find_first();
    assert(next_sum != SUM);
    sizes.push_back(sum - next_sum);
    sum = next_sum;
    --size;
  }
  sort(sizes.rbegin(), sizes.rend());  
  //reverse(sizes.begin(), sizes.end());
  priority_queue<array<int, 2>> pq;
  for (int i = 0; i < N; ++i) {
    pq.push({A[i], i});
  }
  cout << int(sizes.size()) << '\n';
  for (auto s : sizes) {
    cout << s << ' ';
    vector<array<int, 2>> temp;
    for (int j = 0; j < s; ++j) {
      auto t = pq.top(); pq.pop();
      cout << t[1] + 1 << ' ';
      temp.push_back(t);
    }
    cout << '\n';
    for (auto t : temp) {
      t[0] -= 1;
      if (t[0] > 0) pq.push(t);
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 27992 KB Output is correct
2 Correct 21 ms 28208 KB Output is correct
3 Correct 18 ms 27996 KB Output is correct
4 Correct 14 ms 27892 KB Output is correct
5 Correct 22 ms 27968 KB Output is correct
6 Correct 17 ms 27992 KB Output is correct
7 Correct 22 ms 27996 KB Output is correct
8 Correct 23 ms 27956 KB Output is correct
9 Correct 14 ms 27996 KB Output is correct
10 Correct 85 ms 28056 KB Output is correct
11 Correct 16 ms 27996 KB Output is correct
12 Correct 37 ms 27996 KB Output is correct
13 Correct 17 ms 27996 KB Output is correct
14 Correct 18 ms 27892 KB Output is correct
15 Correct 17 ms 27996 KB Output is correct
16 Correct 18 ms 27992 KB Output is correct
17 Correct 13 ms 27980 KB Output is correct
18 Correct 18 ms 27996 KB Output is correct
19 Correct 12 ms 27992 KB Output is correct
20 Correct 11 ms 28008 KB Output is correct
21 Correct 17 ms 27992 KB Output is correct
22 Correct 41 ms 27992 KB Output is correct
23 Correct 34 ms 27992 KB Output is correct
24 Correct 21 ms 27996 KB Output is correct
25 Correct 20 ms 28136 KB Output is correct
26 Correct 12 ms 27992 KB Output is correct
27 Correct 12 ms 27992 KB Output is correct
28 Correct 16 ms 27996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27880 KB Output is correct
2 Correct 18 ms 28008 KB Output is correct
3 Correct 18 ms 27996 KB Output is correct
4 Correct 15 ms 27996 KB Output is correct
5 Correct 19 ms 27992 KB Output is correct
6 Correct 13 ms 27992 KB Output is correct
7 Correct 18 ms 27996 KB Output is correct
8 Correct 23 ms 27996 KB Output is correct
9 Correct 20 ms 27996 KB Output is correct
10 Correct 29 ms 28240 KB Output is correct
11 Correct 18 ms 27996 KB Output is correct
12 Correct 16 ms 27996 KB Output is correct
13 Correct 18 ms 27956 KB Output is correct
14 Correct 13 ms 27992 KB Output is correct
15 Correct 15 ms 28248 KB Output is correct
16 Correct 11 ms 27996 KB Output is correct
17 Correct 11 ms 27996 KB Output is correct
18 Correct 16 ms 27996 KB Output is correct
19 Correct 18 ms 28252 KB Output is correct
20 Correct 12 ms 27944 KB Output is correct
21 Correct 12 ms 27996 KB Output is correct
22 Correct 12 ms 28028 KB Output is correct
23 Correct 11 ms 27996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 27996 KB Output is correct
2 Correct 15 ms 27996 KB Output is correct
3 Correct 19 ms 27996 KB Output is correct
4 Correct 18 ms 27996 KB Output is correct
5 Correct 15 ms 27992 KB Output is correct
6 Correct 23 ms 28012 KB Output is correct
7 Correct 17 ms 28020 KB Output is correct
8 Correct 27 ms 27996 KB Output is correct
9 Correct 18 ms 27992 KB Output is correct
10 Correct 21 ms 27996 KB Output is correct
11 Correct 15 ms 27996 KB Output is correct
12 Correct 15 ms 27996 KB Output is correct
13 Correct 13 ms 27996 KB Output is correct
14 Correct 15 ms 27996 KB Output is correct
15 Correct 23 ms 27996 KB Output is correct
16 Correct 17 ms 27996 KB Output is correct
17 Runtime error 45 ms 56488 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 27992 KB Output is correct
2 Correct 21 ms 28208 KB Output is correct
3 Correct 18 ms 27996 KB Output is correct
4 Correct 14 ms 27892 KB Output is correct
5 Correct 22 ms 27968 KB Output is correct
6 Correct 17 ms 27992 KB Output is correct
7 Correct 22 ms 27996 KB Output is correct
8 Correct 23 ms 27956 KB Output is correct
9 Correct 14 ms 27996 KB Output is correct
10 Correct 85 ms 28056 KB Output is correct
11 Correct 16 ms 27996 KB Output is correct
12 Correct 37 ms 27996 KB Output is correct
13 Correct 17 ms 27996 KB Output is correct
14 Correct 18 ms 27892 KB Output is correct
15 Correct 17 ms 27996 KB Output is correct
16 Correct 18 ms 27992 KB Output is correct
17 Correct 13 ms 27980 KB Output is correct
18 Correct 18 ms 27996 KB Output is correct
19 Correct 12 ms 27992 KB Output is correct
20 Correct 11 ms 28008 KB Output is correct
21 Correct 17 ms 27992 KB Output is correct
22 Correct 41 ms 27992 KB Output is correct
23 Correct 34 ms 27992 KB Output is correct
24 Correct 21 ms 27996 KB Output is correct
25 Correct 20 ms 28136 KB Output is correct
26 Correct 12 ms 27992 KB Output is correct
27 Correct 12 ms 27992 KB Output is correct
28 Correct 16 ms 27996 KB Output is correct
29 Correct 27 ms 27996 KB Output is correct
30 Correct 15 ms 27996 KB Output is correct
31 Correct 19 ms 27996 KB Output is correct
32 Correct 18 ms 27996 KB Output is correct
33 Correct 15 ms 27992 KB Output is correct
34 Correct 23 ms 28012 KB Output is correct
35 Correct 17 ms 28020 KB Output is correct
36 Correct 27 ms 27996 KB Output is correct
37 Correct 18 ms 27992 KB Output is correct
38 Correct 21 ms 27996 KB Output is correct
39 Correct 15 ms 27996 KB Output is correct
40 Correct 15 ms 27996 KB Output is correct
41 Correct 13 ms 27996 KB Output is correct
42 Correct 15 ms 27996 KB Output is correct
43 Correct 23 ms 27996 KB Output is correct
44 Correct 17 ms 27996 KB Output is correct
45 Runtime error 45 ms 56488 KB Execution killed with signal 6
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 27992 KB Output is correct
2 Correct 21 ms 28208 KB Output is correct
3 Correct 18 ms 27996 KB Output is correct
4 Correct 14 ms 27892 KB Output is correct
5 Correct 22 ms 27968 KB Output is correct
6 Correct 17 ms 27992 KB Output is correct
7 Correct 22 ms 27996 KB Output is correct
8 Correct 23 ms 27956 KB Output is correct
9 Correct 14 ms 27996 KB Output is correct
10 Correct 85 ms 28056 KB Output is correct
11 Correct 16 ms 27996 KB Output is correct
12 Correct 37 ms 27996 KB Output is correct
13 Correct 17 ms 27996 KB Output is correct
14 Correct 18 ms 27892 KB Output is correct
15 Correct 17 ms 27996 KB Output is correct
16 Correct 18 ms 27992 KB Output is correct
17 Correct 13 ms 27980 KB Output is correct
18 Correct 18 ms 27996 KB Output is correct
19 Correct 12 ms 27992 KB Output is correct
20 Correct 11 ms 28008 KB Output is correct
21 Correct 17 ms 27992 KB Output is correct
22 Correct 41 ms 27992 KB Output is correct
23 Correct 34 ms 27992 KB Output is correct
24 Correct 21 ms 27996 KB Output is correct
25 Correct 20 ms 28136 KB Output is correct
26 Correct 12 ms 27992 KB Output is correct
27 Correct 12 ms 27992 KB Output is correct
28 Correct 16 ms 27996 KB Output is correct
29 Correct 27 ms 27996 KB Output is correct
30 Correct 15 ms 27996 KB Output is correct
31 Correct 19 ms 27996 KB Output is correct
32 Correct 18 ms 27996 KB Output is correct
33 Correct 15 ms 27992 KB Output is correct
34 Correct 23 ms 28012 KB Output is correct
35 Correct 17 ms 28020 KB Output is correct
36 Correct 27 ms 27996 KB Output is correct
37 Correct 18 ms 27992 KB Output is correct
38 Correct 21 ms 27996 KB Output is correct
39 Correct 15 ms 27996 KB Output is correct
40 Correct 15 ms 27996 KB Output is correct
41 Correct 13 ms 27996 KB Output is correct
42 Correct 15 ms 27996 KB Output is correct
43 Correct 23 ms 27996 KB Output is correct
44 Correct 17 ms 27996 KB Output is correct
45 Runtime error 45 ms 56488 KB Execution killed with signal 6
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 27992 KB Output is correct
2 Correct 21 ms 28208 KB Output is correct
3 Correct 18 ms 27996 KB Output is correct
4 Correct 14 ms 27892 KB Output is correct
5 Correct 22 ms 27968 KB Output is correct
6 Correct 17 ms 27992 KB Output is correct
7 Correct 22 ms 27996 KB Output is correct
8 Correct 23 ms 27956 KB Output is correct
9 Correct 14 ms 27996 KB Output is correct
10 Correct 85 ms 28056 KB Output is correct
11 Correct 16 ms 27996 KB Output is correct
12 Correct 37 ms 27996 KB Output is correct
13 Correct 17 ms 27996 KB Output is correct
14 Correct 18 ms 27892 KB Output is correct
15 Correct 17 ms 27996 KB Output is correct
16 Correct 18 ms 27992 KB Output is correct
17 Correct 13 ms 27980 KB Output is correct
18 Correct 18 ms 27996 KB Output is correct
19 Correct 12 ms 27992 KB Output is correct
20 Correct 11 ms 28008 KB Output is correct
21 Correct 17 ms 27992 KB Output is correct
22 Correct 41 ms 27992 KB Output is correct
23 Correct 34 ms 27992 KB Output is correct
24 Correct 21 ms 27996 KB Output is correct
25 Correct 20 ms 28136 KB Output is correct
26 Correct 12 ms 27992 KB Output is correct
27 Correct 12 ms 27992 KB Output is correct
28 Correct 16 ms 27996 KB Output is correct
29 Correct 13 ms 27880 KB Output is correct
30 Correct 18 ms 28008 KB Output is correct
31 Correct 18 ms 27996 KB Output is correct
32 Correct 15 ms 27996 KB Output is correct
33 Correct 19 ms 27992 KB Output is correct
34 Correct 13 ms 27992 KB Output is correct
35 Correct 18 ms 27996 KB Output is correct
36 Correct 23 ms 27996 KB Output is correct
37 Correct 20 ms 27996 KB Output is correct
38 Correct 29 ms 28240 KB Output is correct
39 Correct 18 ms 27996 KB Output is correct
40 Correct 16 ms 27996 KB Output is correct
41 Correct 18 ms 27956 KB Output is correct
42 Correct 13 ms 27992 KB Output is correct
43 Correct 15 ms 28248 KB Output is correct
44 Correct 11 ms 27996 KB Output is correct
45 Correct 11 ms 27996 KB Output is correct
46 Correct 16 ms 27996 KB Output is correct
47 Correct 18 ms 28252 KB Output is correct
48 Correct 12 ms 27944 KB Output is correct
49 Correct 12 ms 27996 KB Output is correct
50 Correct 12 ms 28028 KB Output is correct
51 Correct 11 ms 27996 KB Output is correct
52 Correct 27 ms 27996 KB Output is correct
53 Correct 15 ms 27996 KB Output is correct
54 Correct 19 ms 27996 KB Output is correct
55 Correct 18 ms 27996 KB Output is correct
56 Correct 15 ms 27992 KB Output is correct
57 Correct 23 ms 28012 KB Output is correct
58 Correct 17 ms 28020 KB Output is correct
59 Correct 27 ms 27996 KB Output is correct
60 Correct 18 ms 27992 KB Output is correct
61 Correct 21 ms 27996 KB Output is correct
62 Correct 15 ms 27996 KB Output is correct
63 Correct 15 ms 27996 KB Output is correct
64 Correct 13 ms 27996 KB Output is correct
65 Correct 15 ms 27996 KB Output is correct
66 Correct 23 ms 27996 KB Output is correct
67 Correct 17 ms 27996 KB Output is correct
68 Runtime error 45 ms 56488 KB Execution killed with signal 6
69 Halted 0 ms 0 KB -