Submission #868534

# Submission time Handle Problem Language Result Execution time Memory
868534 2023-10-31T17:06:36 Z Charizard2021 Bootfall (IZhO17_bootfall) C++17
100 / 100
435 ms 7932 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 250000;
const int M = 1000000;
const int MOD = 1e9 + 7;
int n;
int v[502];
int freq[1 + M];
bool dp[1 + N];
int dp2[1 + N];
int dp3[1 + N];
int firstVal[1 + N];
int lastVal[1 + N];
bool solve(int x){
    int sum = 0;
    for(int i = 1; i <= n; i++){
        if(i != x){
            sum += v[i];
        }
    }
    if(x == 0){
        int maxVal = 0;
        dp[0] = 1;
        dp2[0] = 1;
        for(int i = 1; i <= n; i++){
            for(int j = maxVal; j >= 0; j--){
                if(dp[j]){
                    dp2[j + v[i]] = (dp2[j + v[i]] + dp2[j]) % MOD;
                    if(!firstVal[j + v[i]]){
                        firstVal[j + v[i]] = i;
                    }
                    lastVal[j + v[i]] = i;
                    dp[j + v[i]] = 1;
                }
            }
            maxVal += v[i];
        }
        if(maxVal % 2 == 0 && dp[maxVal/2]){
            return 1;
        }
        return 0;
    }
    else{
        for(int j = 0; j <= sum + v[x]; j++){
            dp3[j] = dp2[j];
        }
        for(int j = v[x]; j <= sum + v[x]; j++){
            dp2[j] = (((dp2[j] - dp2[j - v[x]]) % MOD) + MOD) % MOD;
        }
        for(int i = 0; i <= sum/2; i++){
            if(dp2[i]){
                freq[sum - 2 * i]++;
            }
        }
        for(int j = 0; j <= sum + v[x]; j++){
            dp2[j] = dp3[j];
        }
        return true;
    }
}
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    sort(v + 1, v + n + 1);
    bool thing = solve(0);
    if(thing == false){
        cout << 0 << "\n";
        return 0;
    }
    for(int i = 1; i <= n; i++) solve(i);
    int ans = 0;
    vector<int> val;
    for(int i = 0; i <= M; i++){
        if(freq[i] == n){
            ans++;
            val.push_back(i);
        }
    }
    cout << ans << "\n";
    for(int x : val){
        cout << x << " ";
    }
    cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 3 ms 2480 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2524 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 3 ms 2396 KB Output is correct
8 Correct 4 ms 2540 KB Output is correct
9 Correct 4 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 3 ms 2480 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2524 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 3 ms 2396 KB Output is correct
8 Correct 4 ms 2540 KB Output is correct
9 Correct 4 ms 2392 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2488 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 4 ms 2516 KB Output is correct
14 Correct 4 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 3 ms 2396 KB Output is correct
18 Correct 3 ms 2396 KB Output is correct
19 Correct 4 ms 2396 KB Output is correct
20 Correct 4 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 3 ms 2480 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2524 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 3 ms 2396 KB Output is correct
8 Correct 4 ms 2540 KB Output is correct
9 Correct 4 ms 2392 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2488 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 4 ms 2516 KB Output is correct
14 Correct 4 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 3 ms 2396 KB Output is correct
18 Correct 3 ms 2396 KB Output is correct
19 Correct 4 ms 2396 KB Output is correct
20 Correct 4 ms 2396 KB Output is correct
21 Correct 4 ms 2392 KB Output is correct
22 Correct 4 ms 2396 KB Output is correct
23 Correct 5 ms 2392 KB Output is correct
24 Correct 5 ms 2396 KB Output is correct
25 Correct 6 ms 2652 KB Output is correct
26 Correct 7 ms 2620 KB Output is correct
27 Correct 7 ms 2396 KB Output is correct
28 Correct 7 ms 2396 KB Output is correct
29 Correct 7 ms 2392 KB Output is correct
30 Correct 5 ms 2396 KB Output is correct
31 Correct 6 ms 2492 KB Output is correct
32 Correct 5 ms 2396 KB Output is correct
33 Correct 6 ms 2636 KB Output is correct
34 Correct 6 ms 2632 KB Output is correct
35 Correct 7 ms 2396 KB Output is correct
36 Correct 5 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 3 ms 2480 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2524 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 3 ms 2396 KB Output is correct
8 Correct 4 ms 2540 KB Output is correct
9 Correct 4 ms 2392 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2488 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 4 ms 2516 KB Output is correct
14 Correct 4 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 3 ms 2396 KB Output is correct
18 Correct 3 ms 2396 KB Output is correct
19 Correct 4 ms 2396 KB Output is correct
20 Correct 4 ms 2396 KB Output is correct
21 Correct 4 ms 2392 KB Output is correct
22 Correct 4 ms 2396 KB Output is correct
23 Correct 5 ms 2392 KB Output is correct
24 Correct 5 ms 2396 KB Output is correct
25 Correct 6 ms 2652 KB Output is correct
26 Correct 7 ms 2620 KB Output is correct
27 Correct 7 ms 2396 KB Output is correct
28 Correct 7 ms 2396 KB Output is correct
29 Correct 7 ms 2392 KB Output is correct
30 Correct 5 ms 2396 KB Output is correct
31 Correct 6 ms 2492 KB Output is correct
32 Correct 5 ms 2396 KB Output is correct
33 Correct 6 ms 2636 KB Output is correct
34 Correct 6 ms 2632 KB Output is correct
35 Correct 7 ms 2396 KB Output is correct
36 Correct 5 ms 2396 KB Output is correct
37 Correct 17 ms 2652 KB Output is correct
38 Correct 17 ms 2908 KB Output is correct
39 Correct 51 ms 5212 KB Output is correct
40 Correct 33 ms 4944 KB Output is correct
41 Correct 65 ms 5208 KB Output is correct
42 Correct 30 ms 2836 KB Output is correct
43 Correct 52 ms 5456 KB Output is correct
44 Correct 61 ms 5456 KB Output is correct
45 Correct 54 ms 5456 KB Output is correct
46 Correct 29 ms 2880 KB Output is correct
47 Correct 34 ms 4940 KB Output is correct
48 Correct 56 ms 5516 KB Output is correct
49 Correct 54 ms 5272 KB Output is correct
50 Correct 32 ms 5064 KB Output is correct
51 Correct 6 ms 2652 KB Output is correct
52 Correct 70 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 3 ms 2480 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2524 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 3 ms 2396 KB Output is correct
8 Correct 4 ms 2540 KB Output is correct
9 Correct 4 ms 2392 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2488 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 4 ms 2516 KB Output is correct
14 Correct 4 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 3 ms 2396 KB Output is correct
18 Correct 3 ms 2396 KB Output is correct
19 Correct 4 ms 2396 KB Output is correct
20 Correct 4 ms 2396 KB Output is correct
21 Correct 4 ms 2392 KB Output is correct
22 Correct 4 ms 2396 KB Output is correct
23 Correct 5 ms 2392 KB Output is correct
24 Correct 5 ms 2396 KB Output is correct
25 Correct 6 ms 2652 KB Output is correct
26 Correct 7 ms 2620 KB Output is correct
27 Correct 7 ms 2396 KB Output is correct
28 Correct 7 ms 2396 KB Output is correct
29 Correct 7 ms 2392 KB Output is correct
30 Correct 5 ms 2396 KB Output is correct
31 Correct 6 ms 2492 KB Output is correct
32 Correct 5 ms 2396 KB Output is correct
33 Correct 6 ms 2636 KB Output is correct
34 Correct 6 ms 2632 KB Output is correct
35 Correct 7 ms 2396 KB Output is correct
36 Correct 5 ms 2396 KB Output is correct
37 Correct 17 ms 2652 KB Output is correct
38 Correct 17 ms 2908 KB Output is correct
39 Correct 51 ms 5212 KB Output is correct
40 Correct 33 ms 4944 KB Output is correct
41 Correct 65 ms 5208 KB Output is correct
42 Correct 30 ms 2836 KB Output is correct
43 Correct 52 ms 5456 KB Output is correct
44 Correct 61 ms 5456 KB Output is correct
45 Correct 54 ms 5456 KB Output is correct
46 Correct 29 ms 2880 KB Output is correct
47 Correct 34 ms 4940 KB Output is correct
48 Correct 56 ms 5516 KB Output is correct
49 Correct 54 ms 5272 KB Output is correct
50 Correct 32 ms 5064 KB Output is correct
51 Correct 6 ms 2652 KB Output is correct
52 Correct 70 ms 5716 KB Output is correct
53 Correct 50 ms 5348 KB Output is correct
54 Correct 71 ms 5460 KB Output is correct
55 Correct 142 ms 6096 KB Output is correct
56 Correct 61 ms 5452 KB Output is correct
57 Correct 152 ms 6268 KB Output is correct
58 Correct 76 ms 5536 KB Output is correct
59 Correct 99 ms 5840 KB Output is correct
60 Correct 13 ms 2908 KB Output is correct
61 Correct 110 ms 6032 KB Output is correct
62 Correct 113 ms 6092 KB Output is correct
63 Correct 127 ms 6148 KB Output is correct
64 Correct 119 ms 5988 KB Output is correct
65 Correct 49 ms 4952 KB Output is correct
66 Correct 54 ms 5176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 3 ms 2480 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 2524 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 3 ms 2396 KB Output is correct
8 Correct 4 ms 2540 KB Output is correct
9 Correct 4 ms 2392 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2488 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 4 ms 2516 KB Output is correct
14 Correct 4 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 3 ms 2396 KB Output is correct
18 Correct 3 ms 2396 KB Output is correct
19 Correct 4 ms 2396 KB Output is correct
20 Correct 4 ms 2396 KB Output is correct
21 Correct 4 ms 2392 KB Output is correct
22 Correct 4 ms 2396 KB Output is correct
23 Correct 5 ms 2392 KB Output is correct
24 Correct 5 ms 2396 KB Output is correct
25 Correct 6 ms 2652 KB Output is correct
26 Correct 7 ms 2620 KB Output is correct
27 Correct 7 ms 2396 KB Output is correct
28 Correct 7 ms 2396 KB Output is correct
29 Correct 7 ms 2392 KB Output is correct
30 Correct 5 ms 2396 KB Output is correct
31 Correct 6 ms 2492 KB Output is correct
32 Correct 5 ms 2396 KB Output is correct
33 Correct 6 ms 2636 KB Output is correct
34 Correct 6 ms 2632 KB Output is correct
35 Correct 7 ms 2396 KB Output is correct
36 Correct 5 ms 2396 KB Output is correct
37 Correct 17 ms 2652 KB Output is correct
38 Correct 17 ms 2908 KB Output is correct
39 Correct 51 ms 5212 KB Output is correct
40 Correct 33 ms 4944 KB Output is correct
41 Correct 65 ms 5208 KB Output is correct
42 Correct 30 ms 2836 KB Output is correct
43 Correct 52 ms 5456 KB Output is correct
44 Correct 61 ms 5456 KB Output is correct
45 Correct 54 ms 5456 KB Output is correct
46 Correct 29 ms 2880 KB Output is correct
47 Correct 34 ms 4940 KB Output is correct
48 Correct 56 ms 5516 KB Output is correct
49 Correct 54 ms 5272 KB Output is correct
50 Correct 32 ms 5064 KB Output is correct
51 Correct 6 ms 2652 KB Output is correct
52 Correct 70 ms 5716 KB Output is correct
53 Correct 50 ms 5348 KB Output is correct
54 Correct 71 ms 5460 KB Output is correct
55 Correct 142 ms 6096 KB Output is correct
56 Correct 61 ms 5452 KB Output is correct
57 Correct 152 ms 6268 KB Output is correct
58 Correct 76 ms 5536 KB Output is correct
59 Correct 99 ms 5840 KB Output is correct
60 Correct 13 ms 2908 KB Output is correct
61 Correct 110 ms 6032 KB Output is correct
62 Correct 113 ms 6092 KB Output is correct
63 Correct 127 ms 6148 KB Output is correct
64 Correct 119 ms 5988 KB Output is correct
65 Correct 49 ms 4952 KB Output is correct
66 Correct 54 ms 5176 KB Output is correct
67 Correct 112 ms 5856 KB Output is correct
68 Correct 31 ms 3228 KB Output is correct
69 Correct 397 ms 7508 KB Output is correct
70 Correct 229 ms 6608 KB Output is correct
71 Correct 216 ms 6420 KB Output is correct
72 Correct 212 ms 5708 KB Output is correct
73 Correct 218 ms 5968 KB Output is correct
74 Correct 412 ms 7708 KB Output is correct
75 Correct 318 ms 7028 KB Output is correct
76 Correct 434 ms 7932 KB Output is correct
77 Correct 435 ms 7884 KB Output is correct