답안 #899539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899539 2024-01-06T12:02:59 Z marcid Bootfall (IZhO17_bootfall) C++17
100 / 100
255 ms 22500 KB
//credits to Sunnatov
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define vb vector<bool>
#define pb push_back
#define eb emplace_back
const int maxn = 25e4+5;
const int sq = 23;
const int inf = 1e18;

void solve() {
    int n; cin >> n;
    int sum = 0;
    vi a(n);
    for (int &i : a) cin >> i, sum+=i;
    set<int> ans;
    bitset<maxn> bs; 
    bs.set(0);
    vector<bitset<maxn>> without(sq), without2(n);
    for (int i : a) bs |= bs << i; //if we can make x, without a[i], we can make x+a[i] with a[i]
    for (int i = 0; i < sq; i++) {
        without[i].set(0);
        for (int j = 0; j < n; j++) {
            if (i*sq <= j && j < (i+1)*sq) continue; //if the block has j-th element, we skip
            without[i] |= without[i] << a[j]; //storing all sums we can get without block of a[j]
        }
    } for (int i = 0; i < n; i++) { //now we do the same thing for each element in each block
        without2[i] = without[i/sq]; //we restore for each block
        for (int j = i/sq*sq; j < min(n,(i/sq+1)*sq); j++) { //in this block, we store values we can get without a[i]
            if (i == j) continue;
            without2[i] |= without2[i] << a[j];
        }
    } for (int i = 1; i <= maxn; i++) { //find values that are suitable for every element of a
        if (sum&1 or !bs[sum/2]) continue;
        sum += i; bool ok = true;
        for (int j = 0; ok and j < n; j++) {
            sum -= a[j];
            if (sum&1 or !without2[j][sum/2]) ok=false;
            sum += a[j];
        }
        sum -= i;
        if (ok) ans.insert(i);
    }
    //out:
    cout<<ans.size()<<'\n';
    for(int i:ans)cout<<i<<' ';
}

signed main() {
    cin.tie()->sync_with_stdio(0);
    int tc = 1;
    //cin >> tc;
    while (tc--) {
        solve();
        cout<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 2 ms 1368 KB Output is correct
5 Correct 3 ms 1624 KB Output is correct
6 Correct 2 ms 1368 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 3 ms 1628 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 2 ms 1368 KB Output is correct
5 Correct 3 ms 1624 KB Output is correct
6 Correct 2 ms 1368 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 3 ms 1628 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 8 ms 2140 KB Output is correct
11 Correct 8 ms 2148 KB Output is correct
12 Correct 9 ms 2140 KB Output is correct
13 Correct 8 ms 2064 KB Output is correct
14 Correct 8 ms 1880 KB Output is correct
15 Correct 8 ms 1884 KB Output is correct
16 Correct 8 ms 2140 KB Output is correct
17 Correct 5 ms 1628 KB Output is correct
18 Correct 7 ms 1996 KB Output is correct
19 Correct 8 ms 1824 KB Output is correct
20 Correct 9 ms 2036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 2 ms 1368 KB Output is correct
5 Correct 3 ms 1624 KB Output is correct
6 Correct 2 ms 1368 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 3 ms 1628 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 8 ms 2140 KB Output is correct
11 Correct 8 ms 2148 KB Output is correct
12 Correct 9 ms 2140 KB Output is correct
13 Correct 8 ms 2064 KB Output is correct
14 Correct 8 ms 1880 KB Output is correct
15 Correct 8 ms 1884 KB Output is correct
16 Correct 8 ms 2140 KB Output is correct
17 Correct 5 ms 1628 KB Output is correct
18 Correct 7 ms 1996 KB Output is correct
19 Correct 8 ms 1824 KB Output is correct
20 Correct 9 ms 2036 KB Output is correct
21 Correct 22 ms 3164 KB Output is correct
22 Correct 20 ms 3416 KB Output is correct
23 Correct 14 ms 2652 KB Output is correct
24 Correct 26 ms 4176 KB Output is correct
25 Correct 26 ms 4184 KB Output is correct
26 Correct 27 ms 4444 KB Output is correct
27 Correct 27 ms 4324 KB Output is correct
28 Correct 28 ms 4316 KB Output is correct
29 Correct 26 ms 4184 KB Output is correct
30 Correct 26 ms 4184 KB Output is correct
31 Correct 28 ms 4572 KB Output is correct
32 Correct 27 ms 4188 KB Output is correct
33 Correct 26 ms 4188 KB Output is correct
34 Correct 26 ms 4188 KB Output is correct
35 Correct 26 ms 4184 KB Output is correct
36 Correct 35 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 2 ms 1368 KB Output is correct
5 Correct 3 ms 1624 KB Output is correct
6 Correct 2 ms 1368 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 3 ms 1628 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 8 ms 2140 KB Output is correct
11 Correct 8 ms 2148 KB Output is correct
12 Correct 9 ms 2140 KB Output is correct
13 Correct 8 ms 2064 KB Output is correct
14 Correct 8 ms 1880 KB Output is correct
15 Correct 8 ms 1884 KB Output is correct
16 Correct 8 ms 2140 KB Output is correct
17 Correct 5 ms 1628 KB Output is correct
18 Correct 7 ms 1996 KB Output is correct
19 Correct 8 ms 1824 KB Output is correct
20 Correct 9 ms 2036 KB Output is correct
21 Correct 22 ms 3164 KB Output is correct
22 Correct 20 ms 3416 KB Output is correct
23 Correct 14 ms 2652 KB Output is correct
24 Correct 26 ms 4176 KB Output is correct
25 Correct 26 ms 4184 KB Output is correct
26 Correct 27 ms 4444 KB Output is correct
27 Correct 27 ms 4324 KB Output is correct
28 Correct 28 ms 4316 KB Output is correct
29 Correct 26 ms 4184 KB Output is correct
30 Correct 26 ms 4184 KB Output is correct
31 Correct 28 ms 4572 KB Output is correct
32 Correct 27 ms 4188 KB Output is correct
33 Correct 26 ms 4188 KB Output is correct
34 Correct 26 ms 4188 KB Output is correct
35 Correct 26 ms 4184 KB Output is correct
36 Correct 35 ms 4444 KB Output is correct
37 Correct 56 ms 7628 KB Output is correct
38 Correct 61 ms 8016 KB Output is correct
39 Correct 65 ms 8792 KB Output is correct
40 Correct 78 ms 10272 KB Output is correct
41 Correct 73 ms 9500 KB Output is correct
42 Correct 73 ms 9652 KB Output is correct
43 Correct 82 ms 9988 KB Output is correct
44 Correct 77 ms 10064 KB Output is correct
45 Correct 79 ms 10184 KB Output is correct
46 Correct 69 ms 9496 KB Output is correct
47 Correct 72 ms 9552 KB Output is correct
48 Correct 75 ms 9808 KB Output is correct
49 Correct 68 ms 8904 KB Output is correct
50 Correct 73 ms 9652 KB Output is correct
51 Correct 65 ms 8888 KB Output is correct
52 Correct 87 ms 10836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 2 ms 1368 KB Output is correct
5 Correct 3 ms 1624 KB Output is correct
6 Correct 2 ms 1368 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 3 ms 1628 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 8 ms 2140 KB Output is correct
11 Correct 8 ms 2148 KB Output is correct
12 Correct 9 ms 2140 KB Output is correct
13 Correct 8 ms 2064 KB Output is correct
14 Correct 8 ms 1880 KB Output is correct
15 Correct 8 ms 1884 KB Output is correct
16 Correct 8 ms 2140 KB Output is correct
17 Correct 5 ms 1628 KB Output is correct
18 Correct 7 ms 1996 KB Output is correct
19 Correct 8 ms 1824 KB Output is correct
20 Correct 9 ms 2036 KB Output is correct
21 Correct 22 ms 3164 KB Output is correct
22 Correct 20 ms 3416 KB Output is correct
23 Correct 14 ms 2652 KB Output is correct
24 Correct 26 ms 4176 KB Output is correct
25 Correct 26 ms 4184 KB Output is correct
26 Correct 27 ms 4444 KB Output is correct
27 Correct 27 ms 4324 KB Output is correct
28 Correct 28 ms 4316 KB Output is correct
29 Correct 26 ms 4184 KB Output is correct
30 Correct 26 ms 4184 KB Output is correct
31 Correct 28 ms 4572 KB Output is correct
32 Correct 27 ms 4188 KB Output is correct
33 Correct 26 ms 4188 KB Output is correct
34 Correct 26 ms 4188 KB Output is correct
35 Correct 26 ms 4184 KB Output is correct
36 Correct 35 ms 4444 KB Output is correct
37 Correct 56 ms 7628 KB Output is correct
38 Correct 61 ms 8016 KB Output is correct
39 Correct 65 ms 8792 KB Output is correct
40 Correct 78 ms 10272 KB Output is correct
41 Correct 73 ms 9500 KB Output is correct
42 Correct 73 ms 9652 KB Output is correct
43 Correct 82 ms 9988 KB Output is correct
44 Correct 77 ms 10064 KB Output is correct
45 Correct 79 ms 10184 KB Output is correct
46 Correct 69 ms 9496 KB Output is correct
47 Correct 72 ms 9552 KB Output is correct
48 Correct 75 ms 9808 KB Output is correct
49 Correct 68 ms 8904 KB Output is correct
50 Correct 73 ms 9652 KB Output is correct
51 Correct 65 ms 8888 KB Output is correct
52 Correct 87 ms 10836 KB Output is correct
53 Correct 92 ms 11460 KB Output is correct
54 Correct 109 ms 13396 KB Output is correct
55 Correct 127 ms 14416 KB Output is correct
56 Correct 96 ms 11888 KB Output is correct
57 Correct 127 ms 14508 KB Output is correct
58 Correct 111 ms 13396 KB Output is correct
59 Correct 116 ms 13748 KB Output is correct
60 Correct 91 ms 11944 KB Output is correct
61 Correct 125 ms 13996 KB Output is correct
62 Correct 113 ms 13344 KB Output is correct
63 Correct 114 ms 13396 KB Output is correct
64 Correct 113 ms 13324 KB Output is correct
65 Correct 81 ms 10840 KB Output is correct
66 Correct 82 ms 11000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 2 ms 1368 KB Output is correct
5 Correct 3 ms 1624 KB Output is correct
6 Correct 2 ms 1368 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 3 ms 1628 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 8 ms 2140 KB Output is correct
11 Correct 8 ms 2148 KB Output is correct
12 Correct 9 ms 2140 KB Output is correct
13 Correct 8 ms 2064 KB Output is correct
14 Correct 8 ms 1880 KB Output is correct
15 Correct 8 ms 1884 KB Output is correct
16 Correct 8 ms 2140 KB Output is correct
17 Correct 5 ms 1628 KB Output is correct
18 Correct 7 ms 1996 KB Output is correct
19 Correct 8 ms 1824 KB Output is correct
20 Correct 9 ms 2036 KB Output is correct
21 Correct 22 ms 3164 KB Output is correct
22 Correct 20 ms 3416 KB Output is correct
23 Correct 14 ms 2652 KB Output is correct
24 Correct 26 ms 4176 KB Output is correct
25 Correct 26 ms 4184 KB Output is correct
26 Correct 27 ms 4444 KB Output is correct
27 Correct 27 ms 4324 KB Output is correct
28 Correct 28 ms 4316 KB Output is correct
29 Correct 26 ms 4184 KB Output is correct
30 Correct 26 ms 4184 KB Output is correct
31 Correct 28 ms 4572 KB Output is correct
32 Correct 27 ms 4188 KB Output is correct
33 Correct 26 ms 4188 KB Output is correct
34 Correct 26 ms 4188 KB Output is correct
35 Correct 26 ms 4184 KB Output is correct
36 Correct 35 ms 4444 KB Output is correct
37 Correct 56 ms 7628 KB Output is correct
38 Correct 61 ms 8016 KB Output is correct
39 Correct 65 ms 8792 KB Output is correct
40 Correct 78 ms 10272 KB Output is correct
41 Correct 73 ms 9500 KB Output is correct
42 Correct 73 ms 9652 KB Output is correct
43 Correct 82 ms 9988 KB Output is correct
44 Correct 77 ms 10064 KB Output is correct
45 Correct 79 ms 10184 KB Output is correct
46 Correct 69 ms 9496 KB Output is correct
47 Correct 72 ms 9552 KB Output is correct
48 Correct 75 ms 9808 KB Output is correct
49 Correct 68 ms 8904 KB Output is correct
50 Correct 73 ms 9652 KB Output is correct
51 Correct 65 ms 8888 KB Output is correct
52 Correct 87 ms 10836 KB Output is correct
53 Correct 92 ms 11460 KB Output is correct
54 Correct 109 ms 13396 KB Output is correct
55 Correct 127 ms 14416 KB Output is correct
56 Correct 96 ms 11888 KB Output is correct
57 Correct 127 ms 14508 KB Output is correct
58 Correct 111 ms 13396 KB Output is correct
59 Correct 116 ms 13748 KB Output is correct
60 Correct 91 ms 11944 KB Output is correct
61 Correct 125 ms 13996 KB Output is correct
62 Correct 113 ms 13344 KB Output is correct
63 Correct 114 ms 13396 KB Output is correct
64 Correct 113 ms 13324 KB Output is correct
65 Correct 81 ms 10840 KB Output is correct
66 Correct 82 ms 11000 KB Output is correct
67 Correct 135 ms 15528 KB Output is correct
68 Correct 123 ms 16476 KB Output is correct
69 Correct 253 ms 21780 KB Output is correct
70 Correct 194 ms 19800 KB Output is correct
71 Correct 197 ms 19608 KB Output is correct
72 Correct 125 ms 16536 KB Output is correct
73 Correct 126 ms 16508 KB Output is correct
74 Correct 255 ms 22268 KB Output is correct
75 Correct 214 ms 20820 KB Output is correct
76 Correct 248 ms 21904 KB Output is correct
77 Correct 255 ms 22500 KB Output is correct