답안 #586736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586736 2022-06-30T15:28:30 Z Shin Bootfall (IZhO17_bootfall) C++14
100 / 100
229 ms 3516 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(), x.end()

using namespace std;
template <class X, class Y> bool minimize(X &a, Y b) {
    if (a > b) return a = b, true;
    return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
    if (a < b) return a = b, true;
    return false;
}

const int N = 500 * 500 + 7;
int n;
int sum;
int a[N];
int cnt[N];

void solve(int l, int r, bitset<N> &dp) {
  if (l == r) {
    for (int i = 0; i < N; i ++) {
      int cur = sum - a[l] - i * 2;
      if (cur >= 0) {
        cnt[cur] += dp[i];
      }
    }
    return;
  }
  int mid = (l + r) >> 1;
  bitset<N> tmp = dp;
  for (int i = l; i <= mid; i ++) {
    tmp |= (tmp << a[i]);
  }
  solve(mid + 1, r, tmp);
  for (int i = mid + 1; i <= r; i ++) {
    dp |= (dp << a[i]);
  }
  solve(l, mid, dp);
}

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i ++) {
    cin >> a[i];
  }
  sum = accumulate(a + 1, a + n + 1, 0);
  bitset<N> dp;
  dp[0] = 1;
  for (int i = 1; i <= n; i ++) {
    dp |= (dp << a[i]);
  }
  if ((sum & 1) || !dp[sum / 2]) {
    return cout << 0, 0;
  }
  dp.reset();
  dp[0] = 1;
  solve(1, n, dp);
  vector<int> res;
  for (int j = 0; j < N; j ++) {
    if (cnt[j] == n) {
      res.push_back(j);
    }
  }
  cout << (int) res.size() << '\n';
  for (int x: res) {
    cout << x << ' ';
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 4 ms 784 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 4 ms 784 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 14 ms 980 KB Output is correct
11 Correct 10 ms 852 KB Output is correct
12 Correct 10 ms 852 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 11 ms 852 KB Output is correct
15 Correct 10 ms 852 KB Output is correct
16 Correct 10 ms 852 KB Output is correct
17 Correct 8 ms 852 KB Output is correct
18 Correct 12 ms 852 KB Output is correct
19 Correct 9 ms 976 KB Output is correct
20 Correct 11 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 4 ms 784 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 14 ms 980 KB Output is correct
11 Correct 10 ms 852 KB Output is correct
12 Correct 10 ms 852 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 11 ms 852 KB Output is correct
15 Correct 10 ms 852 KB Output is correct
16 Correct 10 ms 852 KB Output is correct
17 Correct 8 ms 852 KB Output is correct
18 Correct 12 ms 852 KB Output is correct
19 Correct 9 ms 976 KB Output is correct
20 Correct 11 ms 852 KB Output is correct
21 Correct 23 ms 1068 KB Output is correct
22 Correct 29 ms 1156 KB Output is correct
23 Correct 17 ms 1064 KB Output is correct
24 Correct 33 ms 1160 KB Output is correct
25 Correct 36 ms 1168 KB Output is correct
26 Correct 38 ms 1176 KB Output is correct
27 Correct 32 ms 1180 KB Output is correct
28 Correct 32 ms 1192 KB Output is correct
29 Correct 32 ms 1184 KB Output is correct
30 Correct 43 ms 1152 KB Output is correct
31 Correct 50 ms 1172 KB Output is correct
32 Correct 41 ms 1152 KB Output is correct
33 Correct 33 ms 1108 KB Output is correct
34 Correct 33 ms 1108 KB Output is correct
35 Correct 32 ms 1184 KB Output is correct
36 Correct 33 ms 1160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 4 ms 784 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 14 ms 980 KB Output is correct
11 Correct 10 ms 852 KB Output is correct
12 Correct 10 ms 852 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 11 ms 852 KB Output is correct
15 Correct 10 ms 852 KB Output is correct
16 Correct 10 ms 852 KB Output is correct
17 Correct 8 ms 852 KB Output is correct
18 Correct 12 ms 852 KB Output is correct
19 Correct 9 ms 976 KB Output is correct
20 Correct 11 ms 852 KB Output is correct
21 Correct 23 ms 1068 KB Output is correct
22 Correct 29 ms 1156 KB Output is correct
23 Correct 17 ms 1064 KB Output is correct
24 Correct 33 ms 1160 KB Output is correct
25 Correct 36 ms 1168 KB Output is correct
26 Correct 38 ms 1176 KB Output is correct
27 Correct 32 ms 1180 KB Output is correct
28 Correct 32 ms 1192 KB Output is correct
29 Correct 32 ms 1184 KB Output is correct
30 Correct 43 ms 1152 KB Output is correct
31 Correct 50 ms 1172 KB Output is correct
32 Correct 41 ms 1152 KB Output is correct
33 Correct 33 ms 1108 KB Output is correct
34 Correct 33 ms 1108 KB Output is correct
35 Correct 32 ms 1184 KB Output is correct
36 Correct 33 ms 1160 KB Output is correct
37 Correct 65 ms 1436 KB Output is correct
38 Correct 68 ms 1428 KB Output is correct
39 Correct 83 ms 1468 KB Output is correct
40 Correct 93 ms 1568 KB Output is correct
41 Correct 91 ms 1692 KB Output is correct
42 Correct 88 ms 1472 KB Output is correct
43 Correct 83 ms 1828 KB Output is correct
44 Correct 79 ms 1712 KB Output is correct
45 Correct 88 ms 1716 KB Output is correct
46 Correct 91 ms 1484 KB Output is correct
47 Correct 93 ms 1496 KB Output is correct
48 Correct 81 ms 1716 KB Output is correct
49 Correct 80 ms 1484 KB Output is correct
50 Correct 83 ms 1484 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 97 ms 1980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 4 ms 784 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 14 ms 980 KB Output is correct
11 Correct 10 ms 852 KB Output is correct
12 Correct 10 ms 852 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 11 ms 852 KB Output is correct
15 Correct 10 ms 852 KB Output is correct
16 Correct 10 ms 852 KB Output is correct
17 Correct 8 ms 852 KB Output is correct
18 Correct 12 ms 852 KB Output is correct
19 Correct 9 ms 976 KB Output is correct
20 Correct 11 ms 852 KB Output is correct
21 Correct 23 ms 1068 KB Output is correct
22 Correct 29 ms 1156 KB Output is correct
23 Correct 17 ms 1064 KB Output is correct
24 Correct 33 ms 1160 KB Output is correct
25 Correct 36 ms 1168 KB Output is correct
26 Correct 38 ms 1176 KB Output is correct
27 Correct 32 ms 1180 KB Output is correct
28 Correct 32 ms 1192 KB Output is correct
29 Correct 32 ms 1184 KB Output is correct
30 Correct 43 ms 1152 KB Output is correct
31 Correct 50 ms 1172 KB Output is correct
32 Correct 41 ms 1152 KB Output is correct
33 Correct 33 ms 1108 KB Output is correct
34 Correct 33 ms 1108 KB Output is correct
35 Correct 32 ms 1184 KB Output is correct
36 Correct 33 ms 1160 KB Output is correct
37 Correct 65 ms 1436 KB Output is correct
38 Correct 68 ms 1428 KB Output is correct
39 Correct 83 ms 1468 KB Output is correct
40 Correct 93 ms 1568 KB Output is correct
41 Correct 91 ms 1692 KB Output is correct
42 Correct 88 ms 1472 KB Output is correct
43 Correct 83 ms 1828 KB Output is correct
44 Correct 79 ms 1712 KB Output is correct
45 Correct 88 ms 1716 KB Output is correct
46 Correct 91 ms 1484 KB Output is correct
47 Correct 93 ms 1496 KB Output is correct
48 Correct 81 ms 1716 KB Output is correct
49 Correct 80 ms 1484 KB Output is correct
50 Correct 83 ms 1484 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 97 ms 1980 KB Output is correct
53 Correct 97 ms 1748 KB Output is correct
54 Correct 113 ms 1880 KB Output is correct
55 Correct 127 ms 2268 KB Output is correct
56 Correct 107 ms 1916 KB Output is correct
57 Correct 124 ms 2512 KB Output is correct
58 Correct 134 ms 1936 KB Output is correct
59 Correct 125 ms 2008 KB Output is correct
60 Correct 3 ms 340 KB Output is correct
61 Correct 120 ms 2176 KB Output is correct
62 Correct 109 ms 2208 KB Output is correct
63 Correct 107 ms 2248 KB Output is correct
64 Correct 104 ms 2232 KB Output is correct
65 Correct 104 ms 1512 KB Output is correct
66 Correct 139 ms 1572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 4 ms 784 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 14 ms 980 KB Output is correct
11 Correct 10 ms 852 KB Output is correct
12 Correct 10 ms 852 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 11 ms 852 KB Output is correct
15 Correct 10 ms 852 KB Output is correct
16 Correct 10 ms 852 KB Output is correct
17 Correct 8 ms 852 KB Output is correct
18 Correct 12 ms 852 KB Output is correct
19 Correct 9 ms 976 KB Output is correct
20 Correct 11 ms 852 KB Output is correct
21 Correct 23 ms 1068 KB Output is correct
22 Correct 29 ms 1156 KB Output is correct
23 Correct 17 ms 1064 KB Output is correct
24 Correct 33 ms 1160 KB Output is correct
25 Correct 36 ms 1168 KB Output is correct
26 Correct 38 ms 1176 KB Output is correct
27 Correct 32 ms 1180 KB Output is correct
28 Correct 32 ms 1192 KB Output is correct
29 Correct 32 ms 1184 KB Output is correct
30 Correct 43 ms 1152 KB Output is correct
31 Correct 50 ms 1172 KB Output is correct
32 Correct 41 ms 1152 KB Output is correct
33 Correct 33 ms 1108 KB Output is correct
34 Correct 33 ms 1108 KB Output is correct
35 Correct 32 ms 1184 KB Output is correct
36 Correct 33 ms 1160 KB Output is correct
37 Correct 65 ms 1436 KB Output is correct
38 Correct 68 ms 1428 KB Output is correct
39 Correct 83 ms 1468 KB Output is correct
40 Correct 93 ms 1568 KB Output is correct
41 Correct 91 ms 1692 KB Output is correct
42 Correct 88 ms 1472 KB Output is correct
43 Correct 83 ms 1828 KB Output is correct
44 Correct 79 ms 1712 KB Output is correct
45 Correct 88 ms 1716 KB Output is correct
46 Correct 91 ms 1484 KB Output is correct
47 Correct 93 ms 1496 KB Output is correct
48 Correct 81 ms 1716 KB Output is correct
49 Correct 80 ms 1484 KB Output is correct
50 Correct 83 ms 1484 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 97 ms 1980 KB Output is correct
53 Correct 97 ms 1748 KB Output is correct
54 Correct 113 ms 1880 KB Output is correct
55 Correct 127 ms 2268 KB Output is correct
56 Correct 107 ms 1916 KB Output is correct
57 Correct 124 ms 2512 KB Output is correct
58 Correct 134 ms 1936 KB Output is correct
59 Correct 125 ms 2008 KB Output is correct
60 Correct 3 ms 340 KB Output is correct
61 Correct 120 ms 2176 KB Output is correct
62 Correct 109 ms 2208 KB Output is correct
63 Correct 107 ms 2248 KB Output is correct
64 Correct 104 ms 2232 KB Output is correct
65 Correct 104 ms 1512 KB Output is correct
66 Correct 139 ms 1572 KB Output is correct
67 Correct 131 ms 2088 KB Output is correct
68 Correct 5 ms 416 KB Output is correct
69 Correct 184 ms 3300 KB Output is correct
70 Correct 178 ms 2592 KB Output is correct
71 Correct 185 ms 2572 KB Output is correct
72 Correct 169 ms 1808 KB Output is correct
73 Correct 165 ms 1868 KB Output is correct
74 Correct 178 ms 3408 KB Output is correct
75 Correct 229 ms 3052 KB Output is correct
76 Correct 166 ms 3420 KB Output is correct
77 Correct 204 ms 3516 KB Output is correct