Submission #566470

# Submission time Handle Problem Language Result Execution time Memory
566470 2022-05-22T10:41:46 Z birthdaycake Bootfall (IZhO17_bootfall) C++17
100 / 100
953 ms 5764 KB
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
 
 
 

int a[200001],dp[2000001],cnt[2000001];
int sum = 0;

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


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


signed main(){
    boost;
    
    
    
    int n; cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        for(int k = sum; k >= 1; k--){
            if(k - a[i] >= 0){
                dp[k] += dp[k - a[i]];
                dp[k] %= mod;
            }
        }
    }
    if(sum % 2 || dp[sum / 2] == 0){
        cout << 0;
        return 0;
    }
    vector<int>ans;
    for(int i = 0; i < n; i++){
        rem(a[i]);
        sum -= a[i];
        for(int j = 0; j <= sum; j++){
            if(dp[j]){
                int other = sum - j;
                if(other - j <= 0) continue;
                cnt[other - j]++;
                if(cnt[other - j] == n) ans.push_back(other - j);
            }
        }
        put(a[i]);
        sum += a[i];
    }
    sort(ans.begin(),ans.end());
    cout << ans.size() << endl;
    for(auto s:ans) cout << s << ' ' ;
    
    
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 6 ms 460 KB Output is correct
26 Correct 7 ms 468 KB Output is correct
27 Correct 6 ms 468 KB Output is correct
28 Correct 7 ms 468 KB Output is correct
29 Correct 6 ms 468 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 6 ms 468 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 6 ms 468 KB Output is correct
34 Correct 7 ms 452 KB Output is correct
35 Correct 9 ms 468 KB Output is correct
36 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 6 ms 460 KB Output is correct
26 Correct 7 ms 468 KB Output is correct
27 Correct 6 ms 468 KB Output is correct
28 Correct 7 ms 468 KB Output is correct
29 Correct 6 ms 468 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 6 ms 468 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 6 ms 468 KB Output is correct
34 Correct 7 ms 452 KB Output is correct
35 Correct 9 ms 468 KB Output is correct
36 Correct 4 ms 468 KB Output is correct
37 Correct 35 ms 892 KB Output is correct
38 Correct 28 ms 852 KB Output is correct
39 Correct 109 ms 1296 KB Output is correct
40 Correct 67 ms 1088 KB Output is correct
41 Correct 107 ms 1432 KB Output is correct
42 Correct 56 ms 1060 KB Output is correct
43 Correct 97 ms 1580 KB Output is correct
44 Correct 125 ms 1680 KB Output is correct
45 Correct 107 ms 1596 KB Output is correct
46 Correct 53 ms 724 KB Output is correct
47 Correct 56 ms 1104 KB Output is correct
48 Correct 114 ms 1672 KB Output is correct
49 Correct 103 ms 1424 KB Output is correct
50 Correct 60 ms 1096 KB Output is correct
51 Correct 13 ms 584 KB Output is correct
52 Correct 128 ms 1872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 6 ms 460 KB Output is correct
26 Correct 7 ms 468 KB Output is correct
27 Correct 6 ms 468 KB Output is correct
28 Correct 7 ms 468 KB Output is correct
29 Correct 6 ms 468 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 6 ms 468 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 6 ms 468 KB Output is correct
34 Correct 7 ms 452 KB Output is correct
35 Correct 9 ms 468 KB Output is correct
36 Correct 4 ms 468 KB Output is correct
37 Correct 35 ms 892 KB Output is correct
38 Correct 28 ms 852 KB Output is correct
39 Correct 109 ms 1296 KB Output is correct
40 Correct 67 ms 1088 KB Output is correct
41 Correct 107 ms 1432 KB Output is correct
42 Correct 56 ms 1060 KB Output is correct
43 Correct 97 ms 1580 KB Output is correct
44 Correct 125 ms 1680 KB Output is correct
45 Correct 107 ms 1596 KB Output is correct
46 Correct 53 ms 724 KB Output is correct
47 Correct 56 ms 1104 KB Output is correct
48 Correct 114 ms 1672 KB Output is correct
49 Correct 103 ms 1424 KB Output is correct
50 Correct 60 ms 1096 KB Output is correct
51 Correct 13 ms 584 KB Output is correct
52 Correct 128 ms 1872 KB Output is correct
53 Correct 94 ms 1436 KB Output is correct
54 Correct 162 ms 1660 KB Output is correct
55 Correct 265 ms 2892 KB Output is correct
56 Correct 121 ms 1672 KB Output is correct
57 Correct 317 ms 3044 KB Output is correct
58 Correct 155 ms 1828 KB Output is correct
59 Correct 195 ms 2072 KB Output is correct
60 Correct 42 ms 800 KB Output is correct
61 Correct 243 ms 2312 KB Output is correct
62 Correct 223 ms 2588 KB Output is correct
63 Correct 250 ms 2716 KB Output is correct
64 Correct 241 ms 2676 KB Output is correct
65 Correct 104 ms 1080 KB Output is correct
66 Correct 102 ms 1328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 6 ms 460 KB Output is correct
26 Correct 7 ms 468 KB Output is correct
27 Correct 6 ms 468 KB Output is correct
28 Correct 7 ms 468 KB Output is correct
29 Correct 6 ms 468 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 6 ms 468 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 6 ms 468 KB Output is correct
34 Correct 7 ms 452 KB Output is correct
35 Correct 9 ms 468 KB Output is correct
36 Correct 4 ms 468 KB Output is correct
37 Correct 35 ms 892 KB Output is correct
38 Correct 28 ms 852 KB Output is correct
39 Correct 109 ms 1296 KB Output is correct
40 Correct 67 ms 1088 KB Output is correct
41 Correct 107 ms 1432 KB Output is correct
42 Correct 56 ms 1060 KB Output is correct
43 Correct 97 ms 1580 KB Output is correct
44 Correct 125 ms 1680 KB Output is correct
45 Correct 107 ms 1596 KB Output is correct
46 Correct 53 ms 724 KB Output is correct
47 Correct 56 ms 1104 KB Output is correct
48 Correct 114 ms 1672 KB Output is correct
49 Correct 103 ms 1424 KB Output is correct
50 Correct 60 ms 1096 KB Output is correct
51 Correct 13 ms 584 KB Output is correct
52 Correct 128 ms 1872 KB Output is correct
53 Correct 94 ms 1436 KB Output is correct
54 Correct 162 ms 1660 KB Output is correct
55 Correct 265 ms 2892 KB Output is correct
56 Correct 121 ms 1672 KB Output is correct
57 Correct 317 ms 3044 KB Output is correct
58 Correct 155 ms 1828 KB Output is correct
59 Correct 195 ms 2072 KB Output is correct
60 Correct 42 ms 800 KB Output is correct
61 Correct 243 ms 2312 KB Output is correct
62 Correct 223 ms 2588 KB Output is correct
63 Correct 250 ms 2716 KB Output is correct
64 Correct 241 ms 2676 KB Output is correct
65 Correct 104 ms 1080 KB Output is correct
66 Correct 102 ms 1328 KB Output is correct
67 Correct 235 ms 2220 KB Output is correct
68 Correct 120 ms 1292 KB Output is correct
69 Correct 826 ms 5168 KB Output is correct
70 Correct 482 ms 3356 KB Output is correct
71 Correct 493 ms 3168 KB Output is correct
72 Correct 498 ms 2204 KB Output is correct
73 Correct 475 ms 2280 KB Output is correct
74 Correct 914 ms 5488 KB Output is correct
75 Correct 743 ms 4320 KB Output is correct
76 Correct 953 ms 5692 KB Output is correct
77 Correct 933 ms 5764 KB Output is correct