Submission #839815

# Submission time Handle Problem Language Result Execution time Memory
839815 2023-08-30T17:12:49 Z nonono Bootfall (IZhO17_bootfall) C++14
100 / 100
293 ms 2756 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 505;

int n, a[mxN];
int sum = 0;
int dp[mxN * mxN];
bool good[mxN * mxN];

void add(int x) {
    sum += x;
    for(int i = sum; i >= x; i --) dp[i] += dp[i - x];
}

void del(int x) {
    for(int i = x; i <= sum; i ++) dp[i] -= dp[i - x];
    sum -= x;
}

signed main() {
#define taskname ""

    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n;
    
    dp[0] = 1;
    for(int i = 1; i <= n; i ++) {
        cin >> a[i];
        add(a[i]);
    }
    
    if(sum % 2 || !dp[sum / 2]) {
        return cout << 0, 0;
    }
    
    for(int i = 1; i <= sum; i ++) good[i] = true;
        
    for(int i = 1; i <= n; i ++) {
        del(a[i]);
        
        for(int j = 1; j <= sum + a[i]; j ++) {
            good[j] = (good[j] && (sum + j) % 2 == 0 && dp[(sum + j) / 2]);
        }
        
        add(a[i]);
    }
    
    vector<int> choose;
    for(int i = 1; i <= sum; i ++) if(good[i]) choose.push_back(i); 
    
    cout << choose.size() << "\n";
    
    for(int x : choose) cout << x << " ";
    
    return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 328 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 324 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 324 KB Output is correct
33 Correct 2 ms 328 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 2 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 328 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 324 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 324 KB Output is correct
33 Correct 2 ms 328 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 2 ms 328 KB Output is correct
37 Correct 13 ms 588 KB Output is correct
38 Correct 10 ms 560 KB Output is correct
39 Correct 35 ms 552 KB Output is correct
40 Correct 25 ms 612 KB Output is correct
41 Correct 40 ms 596 KB Output is correct
42 Correct 17 ms 596 KB Output is correct
43 Correct 31 ms 856 KB Output is correct
44 Correct 32 ms 992 KB Output is correct
45 Correct 43 ms 972 KB Output is correct
46 Correct 18 ms 496 KB Output is correct
47 Correct 19 ms 620 KB Output is correct
48 Correct 36 ms 876 KB Output is correct
49 Correct 32 ms 616 KB Output is correct
50 Correct 19 ms 580 KB Output is correct
51 Correct 3 ms 340 KB Output is correct
52 Correct 43 ms 1040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 328 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 324 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 324 KB Output is correct
33 Correct 2 ms 328 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 2 ms 328 KB Output is correct
37 Correct 13 ms 588 KB Output is correct
38 Correct 10 ms 560 KB Output is correct
39 Correct 35 ms 552 KB Output is correct
40 Correct 25 ms 612 KB Output is correct
41 Correct 40 ms 596 KB Output is correct
42 Correct 17 ms 596 KB Output is correct
43 Correct 31 ms 856 KB Output is correct
44 Correct 32 ms 992 KB Output is correct
45 Correct 43 ms 972 KB Output is correct
46 Correct 18 ms 496 KB Output is correct
47 Correct 19 ms 620 KB Output is correct
48 Correct 36 ms 876 KB Output is correct
49 Correct 32 ms 616 KB Output is correct
50 Correct 19 ms 580 KB Output is correct
51 Correct 3 ms 340 KB Output is correct
52 Correct 43 ms 1040 KB Output is correct
53 Correct 31 ms 808 KB Output is correct
54 Correct 48 ms 968 KB Output is correct
55 Correct 88 ms 1372 KB Output is correct
56 Correct 38 ms 984 KB Output is correct
57 Correct 92 ms 1536 KB Output is correct
58 Correct 49 ms 1052 KB Output is correct
59 Correct 60 ms 1088 KB Output is correct
60 Correct 7 ms 536 KB Output is correct
61 Correct 69 ms 1248 KB Output is correct
62 Correct 73 ms 1356 KB Output is correct
63 Correct 74 ms 1332 KB Output is correct
64 Correct 74 ms 1340 KB Output is correct
65 Correct 33 ms 568 KB Output is correct
66 Correct 35 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 328 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 324 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 324 KB Output is correct
33 Correct 2 ms 328 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 2 ms 328 KB Output is correct
37 Correct 13 ms 588 KB Output is correct
38 Correct 10 ms 560 KB Output is correct
39 Correct 35 ms 552 KB Output is correct
40 Correct 25 ms 612 KB Output is correct
41 Correct 40 ms 596 KB Output is correct
42 Correct 17 ms 596 KB Output is correct
43 Correct 31 ms 856 KB Output is correct
44 Correct 32 ms 992 KB Output is correct
45 Correct 43 ms 972 KB Output is correct
46 Correct 18 ms 496 KB Output is correct
47 Correct 19 ms 620 KB Output is correct
48 Correct 36 ms 876 KB Output is correct
49 Correct 32 ms 616 KB Output is correct
50 Correct 19 ms 580 KB Output is correct
51 Correct 3 ms 340 KB Output is correct
52 Correct 43 ms 1040 KB Output is correct
53 Correct 31 ms 808 KB Output is correct
54 Correct 48 ms 968 KB Output is correct
55 Correct 88 ms 1372 KB Output is correct
56 Correct 38 ms 984 KB Output is correct
57 Correct 92 ms 1536 KB Output is correct
58 Correct 49 ms 1052 KB Output is correct
59 Correct 60 ms 1088 KB Output is correct
60 Correct 7 ms 536 KB Output is correct
61 Correct 69 ms 1248 KB Output is correct
62 Correct 73 ms 1356 KB Output is correct
63 Correct 74 ms 1332 KB Output is correct
64 Correct 74 ms 1340 KB Output is correct
65 Correct 33 ms 568 KB Output is correct
66 Correct 35 ms 580 KB Output is correct
67 Correct 77 ms 1220 KB Output is correct
68 Correct 19 ms 800 KB Output is correct
69 Correct 244 ms 2508 KB Output is correct
70 Correct 142 ms 1712 KB Output is correct
71 Correct 140 ms 1628 KB Output is correct
72 Correct 129 ms 844 KB Output is correct
73 Correct 125 ms 928 KB Output is correct
74 Correct 257 ms 2640 KB Output is correct
75 Correct 193 ms 2188 KB Output is correct
76 Correct 264 ms 2668 KB Output is correct
77 Correct 293 ms 2756 KB Output is correct