Submission #404450

# Submission time Handle Problem Language Result Execution time Memory
404450 2021-05-14T12:21:51 Z rama_pang Bootfall (IZhO17_bootfall) C++17
100 / 100
618 ms 3452 KB
#include <bits/stdc++.h>
using namespace std;

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

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  const int MAX = accumulate(begin(A), end(A), 0) + 5;
  const int MOD = 1e9 + 7;
  const auto Add = [&](int &a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
  };

  int sum = 0;
  vector<int> dp(MAX);

  dp[0] = 1;

  const auto Insert = [&](int a) {
    sum += a;
    for (int i = MAX - 1; i >= 0; i--) {
      if (i + a < MAX) {
        Add(dp[i + a], dp[i]);
      }
    }
  };

  const auto Delete = [&](int a) {
    sum -= a;
    for (int i = 0; i < MAX; i++) {
      if (i + a < MAX) {
        Add(dp[i + a], MOD - dp[i]);
      }
    }
  };

  for (int i = 0; i < N; i++) {
    Insert(A[i]);
  }

  if (sum % 2 != 0 || dp[sum / 2] == 0) {
    cout << 0 << '\n';
    return 0;
  }

  vector<int> ans(MAX);
  for (int i = 0; i < N; i++) {
    Delete(A[i]);
    for (int j = 1; j < MAX; j++) {
      int nsum = sum + j;
      if (nsum % 2 != 0) continue;
      int need = nsum / 2;
      if ((0 <= need - 0 && need - 0 < MAX && dp[need - 0] != 0) ||
          (0 <= need - j && need - j < MAX && dp[need - j] != 0)) {
        ans[j]++;
      }
    }
    Insert(A[i]);
  }

  vector<int> answer;
  for (int i = 1; i < MAX; i++) {
    if (ans[i] == N) {
      answer.emplace_back(i);
    }
  }

  cout << answer.size() << '\n';
  for (auto a : answer) {
    cout << a << ' ';
  }
  cout << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 8 ms 388 KB Output is correct
27 Correct 6 ms 368 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 388 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 320 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 7 ms 332 KB Output is correct
34 Correct 6 ms 388 KB Output is correct
35 Correct 6 ms 312 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 8 ms 388 KB Output is correct
27 Correct 6 ms 368 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 388 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 320 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 7 ms 332 KB Output is correct
34 Correct 6 ms 388 KB Output is correct
35 Correct 6 ms 312 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
37 Correct 21 ms 588 KB Output is correct
38 Correct 22 ms 588 KB Output is correct
39 Correct 83 ms 688 KB Output is correct
40 Correct 50 ms 688 KB Output is correct
41 Correct 106 ms 844 KB Output is correct
42 Correct 40 ms 680 KB Output is correct
43 Correct 75 ms 1120 KB Output is correct
44 Correct 72 ms 1220 KB Output is correct
45 Correct 73 ms 1140 KB Output is correct
46 Correct 44 ms 540 KB Output is correct
47 Correct 48 ms 676 KB Output is correct
48 Correct 81 ms 1064 KB Output is correct
49 Correct 82 ms 804 KB Output is correct
50 Correct 43 ms 676 KB Output is correct
51 Correct 11 ms 436 KB Output is correct
52 Correct 97 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 8 ms 388 KB Output is correct
27 Correct 6 ms 368 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 388 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 320 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 7 ms 332 KB Output is correct
34 Correct 6 ms 388 KB Output is correct
35 Correct 6 ms 312 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
37 Correct 21 ms 588 KB Output is correct
38 Correct 22 ms 588 KB Output is correct
39 Correct 83 ms 688 KB Output is correct
40 Correct 50 ms 688 KB Output is correct
41 Correct 106 ms 844 KB Output is correct
42 Correct 40 ms 680 KB Output is correct
43 Correct 75 ms 1120 KB Output is correct
44 Correct 72 ms 1220 KB Output is correct
45 Correct 73 ms 1140 KB Output is correct
46 Correct 44 ms 540 KB Output is correct
47 Correct 48 ms 676 KB Output is correct
48 Correct 81 ms 1064 KB Output is correct
49 Correct 82 ms 804 KB Output is correct
50 Correct 43 ms 676 KB Output is correct
51 Correct 11 ms 436 KB Output is correct
52 Correct 97 ms 1236 KB Output is correct
53 Correct 69 ms 936 KB Output is correct
54 Correct 99 ms 1216 KB Output is correct
55 Correct 226 ms 1692 KB Output is correct
56 Correct 86 ms 1076 KB Output is correct
57 Correct 209 ms 1832 KB Output is correct
58 Correct 125 ms 1168 KB Output is correct
59 Correct 155 ms 1292 KB Output is correct
60 Correct 28 ms 460 KB Output is correct
61 Correct 153 ms 1608 KB Output is correct
62 Correct 157 ms 1576 KB Output is correct
63 Correct 178 ms 1608 KB Output is correct
64 Correct 162 ms 1616 KB Output is correct
65 Correct 86 ms 696 KB Output is correct
66 Correct 89 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 8 ms 388 KB Output is correct
27 Correct 6 ms 368 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 388 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 320 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 7 ms 332 KB Output is correct
34 Correct 6 ms 388 KB Output is correct
35 Correct 6 ms 312 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
37 Correct 21 ms 588 KB Output is correct
38 Correct 22 ms 588 KB Output is correct
39 Correct 83 ms 688 KB Output is correct
40 Correct 50 ms 688 KB Output is correct
41 Correct 106 ms 844 KB Output is correct
42 Correct 40 ms 680 KB Output is correct
43 Correct 75 ms 1120 KB Output is correct
44 Correct 72 ms 1220 KB Output is correct
45 Correct 73 ms 1140 KB Output is correct
46 Correct 44 ms 540 KB Output is correct
47 Correct 48 ms 676 KB Output is correct
48 Correct 81 ms 1064 KB Output is correct
49 Correct 82 ms 804 KB Output is correct
50 Correct 43 ms 676 KB Output is correct
51 Correct 11 ms 436 KB Output is correct
52 Correct 97 ms 1236 KB Output is correct
53 Correct 69 ms 936 KB Output is correct
54 Correct 99 ms 1216 KB Output is correct
55 Correct 226 ms 1692 KB Output is correct
56 Correct 86 ms 1076 KB Output is correct
57 Correct 209 ms 1832 KB Output is correct
58 Correct 125 ms 1168 KB Output is correct
59 Correct 155 ms 1292 KB Output is correct
60 Correct 28 ms 460 KB Output is correct
61 Correct 153 ms 1608 KB Output is correct
62 Correct 157 ms 1576 KB Output is correct
63 Correct 178 ms 1608 KB Output is correct
64 Correct 162 ms 1616 KB Output is correct
65 Correct 86 ms 696 KB Output is correct
66 Correct 89 ms 776 KB Output is correct
67 Correct 163 ms 1456 KB Output is correct
68 Correct 86 ms 768 KB Output is correct
69 Correct 527 ms 3188 KB Output is correct
70 Correct 332 ms 2084 KB Output is correct
71 Correct 310 ms 1948 KB Output is correct
72 Correct 311 ms 1196 KB Output is correct
73 Correct 306 ms 1188 KB Output is correct
74 Correct 562 ms 3232 KB Output is correct
75 Correct 439 ms 2608 KB Output is correct
76 Correct 613 ms 3364 KB Output is correct
77 Correct 618 ms 3452 KB Output is correct