Submission #858302

# Submission time Handle Problem Language Result Execution time Memory
858302 2023-10-08T04:55:20 Z Alfraganus Bootfall (IZhO17_bootfall) C++17
100 / 100
877 ms 16948 KB
#include <bits/stdc++.h>
using namespace std;

#define fs first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()

#define print(a)          \
    for(auto x : a)       \
        cout << x << ' '; \
    cout << endl;

#define printmp(a)   \
    for (auto x : a) \
        cout << x.fs << ' ' << x.ss << endl;

void solve(){
    int n, s = 0;
    cin >> n;
    vector<int> a(n);
    bool juft = true, toq = true;
    for(int i = 0; i < n; i ++)
        cin >> a[i], s += a[i], juft &= (a[i] % 2 == 0), toq &= (a[i] % 2 == 1);
    if(s % 2 == 1 or juft == toq){
        cout << 0;
        return;
    }
    vector<bitset<500>> dp(s + 1);
    vector<bool> can(s + 1);
    can[0] = true;
    int s1 = 0;
    for (int i = 0; i < n; i++)
    {
        s1 += a[i];
        for (int j = s1; j >= a[i]; j--)
        {
            if (can[j - a[i]])
            {
                if (!can[j])
                {
                    dp[j] = dp[j - a[i]];
                    dp[j][i] = 1;
                }
                else
                    dp[j] = dp[j] & dp[j - a[i]];
                can[j] = true;
            }
        }
    }
    if(!can[s / 2]){
        cout << 0;
        return;
    }
    vector<int> ans;
    for(int x = 0; x <= s; x ++){
        bool flag = (s - a[0] + x) % 2 == 0;
        for(int j = 0; j < n; j ++){
            if(can[(s - a[j] + x) / 2] and !dp[(s - a[j] + x) / 2][j])
                continue;
            else{
                flag = 0;
                break;
            }
        }
        if(flag)
            ans.push_back(x);
    }
    cout << ans.size() << endl;
    print(ans)
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t --){
        solve();
        cout << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 616 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 616 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 4 ms 604 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 5 ms 968 KB Output is correct
27 Correct 4 ms 968 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 7 ms 860 KB Output is correct
32 Correct 5 ms 708 KB Output is correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 3 ms 1084 KB Output is correct
36 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 616 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 4 ms 604 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 5 ms 968 KB Output is correct
27 Correct 4 ms 968 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 7 ms 860 KB Output is correct
32 Correct 5 ms 708 KB Output is correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 3 ms 1084 KB Output is correct
36 Correct 4 ms 604 KB Output is correct
37 Correct 31 ms 1628 KB Output is correct
38 Correct 32 ms 1764 KB Output is correct
39 Correct 9 ms 4184 KB Output is correct
40 Correct 70 ms 2644 KB Output is correct
41 Correct 11 ms 4956 KB Output is correct
42 Correct 59 ms 2348 KB Output is correct
43 Correct 105 ms 4176 KB Output is correct
44 Correct 103 ms 4236 KB Output is correct
45 Correct 107 ms 4248 KB Output is correct
46 Correct 26 ms 2396 KB Output is correct
47 Correct 68 ms 2484 KB Output is correct
48 Correct 77 ms 4560 KB Output is correct
49 Correct 38 ms 4188 KB Output is correct
50 Correct 67 ms 2520 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 122 ms 5096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 616 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 4 ms 604 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 5 ms 968 KB Output is correct
27 Correct 4 ms 968 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 7 ms 860 KB Output is correct
32 Correct 5 ms 708 KB Output is correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 3 ms 1084 KB Output is correct
36 Correct 4 ms 604 KB Output is correct
37 Correct 31 ms 1628 KB Output is correct
38 Correct 32 ms 1764 KB Output is correct
39 Correct 9 ms 4184 KB Output is correct
40 Correct 70 ms 2644 KB Output is correct
41 Correct 11 ms 4956 KB Output is correct
42 Correct 59 ms 2348 KB Output is correct
43 Correct 105 ms 4176 KB Output is correct
44 Correct 103 ms 4236 KB Output is correct
45 Correct 107 ms 4248 KB Output is correct
46 Correct 26 ms 2396 KB Output is correct
47 Correct 68 ms 2484 KB Output is correct
48 Correct 77 ms 4560 KB Output is correct
49 Correct 38 ms 4188 KB Output is correct
50 Correct 67 ms 2520 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 122 ms 5096 KB Output is correct
53 Correct 113 ms 3412 KB Output is correct
54 Correct 152 ms 4184 KB Output is correct
55 Correct 263 ms 7796 KB Output is correct
56 Correct 140 ms 4176 KB Output is correct
57 Correct 284 ms 8184 KB Output is correct
58 Correct 169 ms 4532 KB Output is correct
59 Correct 214 ms 5600 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 235 ms 6240 KB Output is correct
62 Correct 236 ms 7036 KB Output is correct
63 Correct 243 ms 7632 KB Output is correct
64 Correct 234 ms 7376 KB Output is correct
65 Correct 14 ms 3420 KB Output is correct
66 Correct 33 ms 3792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 616 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 4 ms 604 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 5 ms 968 KB Output is correct
27 Correct 4 ms 968 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 7 ms 860 KB Output is correct
32 Correct 5 ms 708 KB Output is correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 3 ms 1084 KB Output is correct
36 Correct 4 ms 604 KB Output is correct
37 Correct 31 ms 1628 KB Output is correct
38 Correct 32 ms 1764 KB Output is correct
39 Correct 9 ms 4184 KB Output is correct
40 Correct 70 ms 2644 KB Output is correct
41 Correct 11 ms 4956 KB Output is correct
42 Correct 59 ms 2348 KB Output is correct
43 Correct 105 ms 4176 KB Output is correct
44 Correct 103 ms 4236 KB Output is correct
45 Correct 107 ms 4248 KB Output is correct
46 Correct 26 ms 2396 KB Output is correct
47 Correct 68 ms 2484 KB Output is correct
48 Correct 77 ms 4560 KB Output is correct
49 Correct 38 ms 4188 KB Output is correct
50 Correct 67 ms 2520 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 122 ms 5096 KB Output is correct
53 Correct 113 ms 3412 KB Output is correct
54 Correct 152 ms 4184 KB Output is correct
55 Correct 263 ms 7796 KB Output is correct
56 Correct 140 ms 4176 KB Output is correct
57 Correct 284 ms 8184 KB Output is correct
58 Correct 169 ms 4532 KB Output is correct
59 Correct 214 ms 5600 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 235 ms 6240 KB Output is correct
62 Correct 236 ms 7036 KB Output is correct
63 Correct 243 ms 7632 KB Output is correct
64 Correct 234 ms 7376 KB Output is correct
65 Correct 14 ms 3420 KB Output is correct
66 Correct 33 ms 3792 KB Output is correct
67 Correct 197 ms 5848 KB Output is correct
68 Correct 183 ms 8028 KB Output is correct
69 Correct 780 ms 14904 KB Output is correct
70 Correct 515 ms 9116 KB Output is correct
71 Correct 503 ms 8856 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 859 ms 15652 KB Output is correct
75 Correct 678 ms 12240 KB Output is correct
76 Correct 784 ms 16948 KB Output is correct
77 Correct 877 ms 16724 KB Output is correct