Submission #714003

# Submission time Handle Problem Language Result Execution time Memory
714003 2023-03-23T13:08:09 Z Alex_tz307 Bootfall (IZhO17_bootfall) C++17
100 / 100
530 ms 31848 KB
#include <bits/stdc++.h>

using namespace std;

const int kN = 500;
const int kMax = kN * kN;
int a[1 + kN];
bitset<1 + kMax> dp, evenStr, oddStr, pref[1 + kN], suff[1 + kN + 1];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  int sum = 0;

  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
  }

  pref[0][0] = true;

  for (int i = 1; i <= n; ++i) {
    pref[i] = pref[i - 1] | (pref[i - 1] << a[i]);
  }

  suff[n + 1][0] = true;

  for (int i = n; i > 0; --i) {
    suff[i] = suff[i + 1] | (suff[i + 1] << a[i]);
  }

  if (sum % 2 == 1 || !pref[n].test(sum / 2)) {
    cout << "0\n";
    return 0;
  }

  bool even = true, odd = true;

  evenStr.set();
  oddStr.set();

  evenStr[0].flip();

  for (int i = 1; i <= n; ++i) {
    if (i <= n / 2) {
      dp = suff[i + 1];

      for (int j = 1; j < i; ++j) {
        dp |= dp << a[j];
      }
    } else {
      dp = pref[i - 1];

      for (int j = i + 1; j <= n; ++j) {
        dp |= dp << a[j];
      }
    }

    int rest = sum - a[i];

    if (rest % 2 == 0) {
      if (even) {
        evenStr &= dp >> (rest / 2);
      }

      if (odd) {
        odd = false;
        oddStr = 0;
      }
    } else {
      if (odd) {
        oddStr &= dp >> (rest / 2 + 1);
      }

      if (even) {
        even = false;
        evenStr = 0;
      }
    }
  }

  cout << evenStr.count() + oddStr.count() << '\n';

  for (int i = 0; i < kMax; ++i) {
    if (evenStr.test(i)) {
      cout << 2 * i << ' ';
    } else if (oddStr.test(i)) {
      cout << 2 * i + 1 << ' ';
    }
  }

  cout << '\n';

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 2 ms 864 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 772 KB Output is correct
5 Correct 2 ms 1144 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1144 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 2 ms 864 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 772 KB Output is correct
5 Correct 2 ms 1144 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1144 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 4 ms 2260 KB Output is correct
11 Correct 4 ms 2260 KB Output is correct
12 Correct 4 ms 2308 KB Output is correct
13 Correct 3 ms 2004 KB Output is correct
14 Correct 4 ms 2132 KB Output is correct
15 Correct 5 ms 2132 KB Output is correct
16 Correct 4 ms 2260 KB Output is correct
17 Correct 3 ms 1524 KB Output is correct
18 Correct 4 ms 1876 KB Output is correct
19 Correct 4 ms 2004 KB Output is correct
20 Correct 5 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 2 ms 864 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 772 KB Output is correct
5 Correct 2 ms 1144 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1144 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 4 ms 2260 KB Output is correct
11 Correct 4 ms 2260 KB Output is correct
12 Correct 4 ms 2308 KB Output is correct
13 Correct 3 ms 2004 KB Output is correct
14 Correct 4 ms 2132 KB Output is correct
15 Correct 5 ms 2132 KB Output is correct
16 Correct 4 ms 2260 KB Output is correct
17 Correct 3 ms 1524 KB Output is correct
18 Correct 4 ms 1876 KB Output is correct
19 Correct 4 ms 2004 KB Output is correct
20 Correct 5 ms 2252 KB Output is correct
21 Correct 12 ms 4444 KB Output is correct
22 Correct 14 ms 4948 KB Output is correct
23 Correct 9 ms 3584 KB Output is correct
24 Correct 21 ms 6192 KB Output is correct
25 Correct 20 ms 6276 KB Output is correct
26 Correct 24 ms 6640 KB Output is correct
27 Correct 32 ms 6636 KB Output is correct
28 Correct 32 ms 6612 KB Output is correct
29 Correct 23 ms 6644 KB Output is correct
30 Correct 26 ms 6612 KB Output is correct
31 Correct 22 ms 6612 KB Output is correct
32 Correct 22 ms 6612 KB Output is correct
33 Correct 21 ms 6612 KB Output is correct
34 Correct 22 ms 6612 KB Output is correct
35 Correct 23 ms 6524 KB Output is correct
36 Correct 24 ms 6528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 2 ms 864 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 772 KB Output is correct
5 Correct 2 ms 1144 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1144 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 4 ms 2260 KB Output is correct
11 Correct 4 ms 2260 KB Output is correct
12 Correct 4 ms 2308 KB Output is correct
13 Correct 3 ms 2004 KB Output is correct
14 Correct 4 ms 2132 KB Output is correct
15 Correct 5 ms 2132 KB Output is correct
16 Correct 4 ms 2260 KB Output is correct
17 Correct 3 ms 1524 KB Output is correct
18 Correct 4 ms 1876 KB Output is correct
19 Correct 4 ms 2004 KB Output is correct
20 Correct 5 ms 2252 KB Output is correct
21 Correct 12 ms 4444 KB Output is correct
22 Correct 14 ms 4948 KB Output is correct
23 Correct 9 ms 3584 KB Output is correct
24 Correct 21 ms 6192 KB Output is correct
25 Correct 20 ms 6276 KB Output is correct
26 Correct 24 ms 6640 KB Output is correct
27 Correct 32 ms 6636 KB Output is correct
28 Correct 32 ms 6612 KB Output is correct
29 Correct 23 ms 6644 KB Output is correct
30 Correct 26 ms 6612 KB Output is correct
31 Correct 22 ms 6612 KB Output is correct
32 Correct 22 ms 6612 KB Output is correct
33 Correct 21 ms 6612 KB Output is correct
34 Correct 22 ms 6612 KB Output is correct
35 Correct 23 ms 6524 KB Output is correct
36 Correct 24 ms 6528 KB Output is correct
37 Correct 88 ms 12788 KB Output is correct
38 Correct 83 ms 12736 KB Output is correct
39 Correct 118 ms 15636 KB Output is correct
40 Correct 157 ms 17032 KB Output is correct
41 Correct 164 ms 17024 KB Output is correct
42 Correct 138 ms 15812 KB Output is correct
43 Correct 133 ms 15560 KB Output is correct
44 Correct 151 ms 15784 KB Output is correct
45 Correct 129 ms 15924 KB Output is correct
46 Correct 141 ms 16980 KB Output is correct
47 Correct 121 ms 15800 KB Output is correct
48 Correct 117 ms 15800 KB Output is correct
49 Correct 131 ms 15796 KB Output is correct
50 Correct 138 ms 15804 KB Output is correct
51 Correct 12 ms 15684 KB Output is correct
52 Correct 149 ms 17128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 2 ms 864 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 772 KB Output is correct
5 Correct 2 ms 1144 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1144 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 4 ms 2260 KB Output is correct
11 Correct 4 ms 2260 KB Output is correct
12 Correct 4 ms 2308 KB Output is correct
13 Correct 3 ms 2004 KB Output is correct
14 Correct 4 ms 2132 KB Output is correct
15 Correct 5 ms 2132 KB Output is correct
16 Correct 4 ms 2260 KB Output is correct
17 Correct 3 ms 1524 KB Output is correct
18 Correct 4 ms 1876 KB Output is correct
19 Correct 4 ms 2004 KB Output is correct
20 Correct 5 ms 2252 KB Output is correct
21 Correct 12 ms 4444 KB Output is correct
22 Correct 14 ms 4948 KB Output is correct
23 Correct 9 ms 3584 KB Output is correct
24 Correct 21 ms 6192 KB Output is correct
25 Correct 20 ms 6276 KB Output is correct
26 Correct 24 ms 6640 KB Output is correct
27 Correct 32 ms 6636 KB Output is correct
28 Correct 32 ms 6612 KB Output is correct
29 Correct 23 ms 6644 KB Output is correct
30 Correct 26 ms 6612 KB Output is correct
31 Correct 22 ms 6612 KB Output is correct
32 Correct 22 ms 6612 KB Output is correct
33 Correct 21 ms 6612 KB Output is correct
34 Correct 22 ms 6612 KB Output is correct
35 Correct 23 ms 6524 KB Output is correct
36 Correct 24 ms 6528 KB Output is correct
37 Correct 88 ms 12788 KB Output is correct
38 Correct 83 ms 12736 KB Output is correct
39 Correct 118 ms 15636 KB Output is correct
40 Correct 157 ms 17032 KB Output is correct
41 Correct 164 ms 17024 KB Output is correct
42 Correct 138 ms 15812 KB Output is correct
43 Correct 133 ms 15560 KB Output is correct
44 Correct 151 ms 15784 KB Output is correct
45 Correct 129 ms 15924 KB Output is correct
46 Correct 141 ms 16980 KB Output is correct
47 Correct 121 ms 15800 KB Output is correct
48 Correct 117 ms 15800 KB Output is correct
49 Correct 131 ms 15796 KB Output is correct
50 Correct 138 ms 15804 KB Output is correct
51 Correct 12 ms 15684 KB Output is correct
52 Correct 149 ms 17128 KB Output is correct
53 Correct 187 ms 18984 KB Output is correct
54 Correct 229 ms 22044 KB Output is correct
55 Correct 232 ms 22176 KB Output is correct
56 Correct 184 ms 19348 KB Output is correct
57 Correct 227 ms 22172 KB Output is correct
58 Correct 226 ms 22092 KB Output is correct
59 Correct 214 ms 22040 KB Output is correct
60 Correct 16 ms 21672 KB Output is correct
61 Correct 254 ms 22052 KB Output is correct
62 Correct 182 ms 20332 KB Output is correct
63 Correct 192 ms 20332 KB Output is correct
64 Correct 196 ms 19972 KB Output is correct
65 Correct 185 ms 19840 KB Output is correct
66 Correct 176 ms 19480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 2 ms 864 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 772 KB Output is correct
5 Correct 2 ms 1144 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 1144 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 4 ms 2260 KB Output is correct
11 Correct 4 ms 2260 KB Output is correct
12 Correct 4 ms 2308 KB Output is correct
13 Correct 3 ms 2004 KB Output is correct
14 Correct 4 ms 2132 KB Output is correct
15 Correct 5 ms 2132 KB Output is correct
16 Correct 4 ms 2260 KB Output is correct
17 Correct 3 ms 1524 KB Output is correct
18 Correct 4 ms 1876 KB Output is correct
19 Correct 4 ms 2004 KB Output is correct
20 Correct 5 ms 2252 KB Output is correct
21 Correct 12 ms 4444 KB Output is correct
22 Correct 14 ms 4948 KB Output is correct
23 Correct 9 ms 3584 KB Output is correct
24 Correct 21 ms 6192 KB Output is correct
25 Correct 20 ms 6276 KB Output is correct
26 Correct 24 ms 6640 KB Output is correct
27 Correct 32 ms 6636 KB Output is correct
28 Correct 32 ms 6612 KB Output is correct
29 Correct 23 ms 6644 KB Output is correct
30 Correct 26 ms 6612 KB Output is correct
31 Correct 22 ms 6612 KB Output is correct
32 Correct 22 ms 6612 KB Output is correct
33 Correct 21 ms 6612 KB Output is correct
34 Correct 22 ms 6612 KB Output is correct
35 Correct 23 ms 6524 KB Output is correct
36 Correct 24 ms 6528 KB Output is correct
37 Correct 88 ms 12788 KB Output is correct
38 Correct 83 ms 12736 KB Output is correct
39 Correct 118 ms 15636 KB Output is correct
40 Correct 157 ms 17032 KB Output is correct
41 Correct 164 ms 17024 KB Output is correct
42 Correct 138 ms 15812 KB Output is correct
43 Correct 133 ms 15560 KB Output is correct
44 Correct 151 ms 15784 KB Output is correct
45 Correct 129 ms 15924 KB Output is correct
46 Correct 141 ms 16980 KB Output is correct
47 Correct 121 ms 15800 KB Output is correct
48 Correct 117 ms 15800 KB Output is correct
49 Correct 131 ms 15796 KB Output is correct
50 Correct 138 ms 15804 KB Output is correct
51 Correct 12 ms 15684 KB Output is correct
52 Correct 149 ms 17128 KB Output is correct
53 Correct 187 ms 18984 KB Output is correct
54 Correct 229 ms 22044 KB Output is correct
55 Correct 232 ms 22176 KB Output is correct
56 Correct 184 ms 19348 KB Output is correct
57 Correct 227 ms 22172 KB Output is correct
58 Correct 226 ms 22092 KB Output is correct
59 Correct 214 ms 22040 KB Output is correct
60 Correct 16 ms 21672 KB Output is correct
61 Correct 254 ms 22052 KB Output is correct
62 Correct 182 ms 20332 KB Output is correct
63 Correct 192 ms 20332 KB Output is correct
64 Correct 196 ms 19972 KB Output is correct
65 Correct 185 ms 19840 KB Output is correct
66 Correct 176 ms 19480 KB Output is correct
67 Correct 317 ms 25164 KB Output is correct
68 Correct 22 ms 30928 KB Output is correct
69 Correct 441 ms 31724 KB Output is correct
70 Correct 440 ms 31460 KB Output is correct
71 Correct 506 ms 31580 KB Output is correct
72 Correct 438 ms 31076 KB Output is correct
73 Correct 449 ms 30924 KB Output is correct
74 Correct 463 ms 31600 KB Output is correct
75 Correct 467 ms 31472 KB Output is correct
76 Correct 465 ms 31848 KB Output is correct
77 Correct 530 ms 31716 KB Output is correct