Submission #975351

# Submission time Handle Problem Language Result Execution time Memory
975351 2024-05-05T01:55:55 Z 12345678 Bootfall (IZhO17_bootfall) C++17
100 / 100
554 ms 17228 KB
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

const int nx=505, kx=250005;

int n, a[nx], sm;
bitset<kx> dp[nx], l, r;
vector<int> res;

bool valid(int x)
{
    for (int i=1; i<=n; i++) if (((sm-a[i]+x)%2)||(!dp[i][(sm-a[i]+x)/2])) return 0;
    return 1;
}
int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++) cin>>a[i], sm+=a[i];
    for (int i=0; i<=n; i++) dp[i][0]=1;
    l[0]=r[0]=1;
    for (int i=1; i<=n; i++)
    {
        if (i>=n/2) dp[i]=l;
        l=l|(l<<a[i]);
    }
    dp[0]=l;
    for (int i=n; i>=1; i--)
    {
        if (i<n/2) dp[i]=r;
        r=r|(r<<a[i]);
    }
    for (int i=1; i<=n; i++)
    {
        if (i>=n/2) for (int j=i+1; j<=n; j++) dp[i]=dp[i]|(dp[i]<<a[j]);
        else for (int j=1; j<i; j++) dp[i]=dp[i]|(dp[i]<<a[j]);
    }
    if ((sm%2)||!dp[0][sm/2]) return cout<<0, 0;
    for (int i=1; i<kx; i++) if (valid(i)) res.push_back(i);
    cout<<res.size()<<'\n';
    for (auto x:res) cout<<x<<' ';
}

/*
4
1 3 1 5
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 2808 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 2584 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 2808 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 2584 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 3 ms 2648 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 3 ms 2652 KB Output is correct
13 Correct 3 ms 2652 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
15 Correct 3 ms 2648 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 2808 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 2584 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 3 ms 2648 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 3 ms 2652 KB Output is correct
13 Correct 3 ms 2652 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
15 Correct 3 ms 2648 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2672 KB Output is correct
21 Correct 9 ms 2648 KB Output is correct
22 Correct 12 ms 4700 KB Output is correct
23 Correct 7 ms 2652 KB Output is correct
24 Correct 17 ms 4700 KB Output is correct
25 Correct 18 ms 4784 KB Output is correct
26 Correct 20 ms 4796 KB Output is correct
27 Correct 20 ms 4788 KB Output is correct
28 Correct 20 ms 4700 KB Output is correct
29 Correct 20 ms 4696 KB Output is correct
30 Correct 20 ms 4784 KB Output is correct
31 Correct 20 ms 4696 KB Output is correct
32 Correct 20 ms 4700 KB Output is correct
33 Correct 22 ms 4788 KB Output is correct
34 Correct 19 ms 4700 KB Output is correct
35 Correct 19 ms 4696 KB Output is correct
36 Correct 20 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 2808 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 2584 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 3 ms 2648 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 3 ms 2652 KB Output is correct
13 Correct 3 ms 2652 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
15 Correct 3 ms 2648 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2672 KB Output is correct
21 Correct 9 ms 2648 KB Output is correct
22 Correct 12 ms 4700 KB Output is correct
23 Correct 7 ms 2652 KB Output is correct
24 Correct 17 ms 4700 KB Output is correct
25 Correct 18 ms 4784 KB Output is correct
26 Correct 20 ms 4796 KB Output is correct
27 Correct 20 ms 4788 KB Output is correct
28 Correct 20 ms 4700 KB Output is correct
29 Correct 20 ms 4696 KB Output is correct
30 Correct 20 ms 4784 KB Output is correct
31 Correct 20 ms 4696 KB Output is correct
32 Correct 20 ms 4700 KB Output is correct
33 Correct 22 ms 4788 KB Output is correct
34 Correct 19 ms 4700 KB Output is correct
35 Correct 19 ms 4696 KB Output is correct
36 Correct 20 ms 4700 KB Output is correct
37 Correct 75 ms 6812 KB Output is correct
38 Correct 78 ms 6744 KB Output is correct
39 Correct 110 ms 8872 KB Output is correct
40 Correct 135 ms 8876 KB Output is correct
41 Correct 128 ms 8796 KB Output is correct
42 Correct 121 ms 8868 KB Output is correct
43 Correct 115 ms 9044 KB Output is correct
44 Correct 118 ms 9144 KB Output is correct
45 Correct 121 ms 9040 KB Output is correct
46 Correct 126 ms 8796 KB Output is correct
47 Correct 119 ms 9040 KB Output is correct
48 Correct 117 ms 9044 KB Output is correct
49 Correct 112 ms 8864 KB Output is correct
50 Correct 117 ms 9040 KB Output is correct
51 Correct 116 ms 8868 KB Output is correct
52 Correct 141 ms 9044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 2808 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 2584 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 3 ms 2648 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 3 ms 2652 KB Output is correct
13 Correct 3 ms 2652 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
15 Correct 3 ms 2648 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2672 KB Output is correct
21 Correct 9 ms 2648 KB Output is correct
22 Correct 12 ms 4700 KB Output is correct
23 Correct 7 ms 2652 KB Output is correct
24 Correct 17 ms 4700 KB Output is correct
25 Correct 18 ms 4784 KB Output is correct
26 Correct 20 ms 4796 KB Output is correct
27 Correct 20 ms 4788 KB Output is correct
28 Correct 20 ms 4700 KB Output is correct
29 Correct 20 ms 4696 KB Output is correct
30 Correct 20 ms 4784 KB Output is correct
31 Correct 20 ms 4696 KB Output is correct
32 Correct 20 ms 4700 KB Output is correct
33 Correct 22 ms 4788 KB Output is correct
34 Correct 19 ms 4700 KB Output is correct
35 Correct 19 ms 4696 KB Output is correct
36 Correct 20 ms 4700 KB Output is correct
37 Correct 75 ms 6812 KB Output is correct
38 Correct 78 ms 6744 KB Output is correct
39 Correct 110 ms 8872 KB Output is correct
40 Correct 135 ms 8876 KB Output is correct
41 Correct 128 ms 8796 KB Output is correct
42 Correct 121 ms 8868 KB Output is correct
43 Correct 115 ms 9044 KB Output is correct
44 Correct 118 ms 9144 KB Output is correct
45 Correct 121 ms 9040 KB Output is correct
46 Correct 126 ms 8796 KB Output is correct
47 Correct 119 ms 9040 KB Output is correct
48 Correct 117 ms 9044 KB Output is correct
49 Correct 112 ms 8864 KB Output is correct
50 Correct 117 ms 9040 KB Output is correct
51 Correct 116 ms 8868 KB Output is correct
52 Correct 141 ms 9044 KB Output is correct
53 Correct 169 ms 11092 KB Output is correct
54 Correct 234 ms 13396 KB Output is correct
55 Correct 241 ms 13584 KB Output is correct
56 Correct 177 ms 11120 KB Output is correct
57 Correct 248 ms 13808 KB Output is correct
58 Correct 230 ms 13232 KB Output is correct
59 Correct 236 ms 13360 KB Output is correct
60 Correct 212 ms 13140 KB Output is correct
61 Correct 236 ms 13524 KB Output is correct
62 Correct 204 ms 11312 KB Output is correct
63 Correct 204 ms 11476 KB Output is correct
64 Correct 197 ms 11476 KB Output is correct
65 Correct 176 ms 11088 KB Output is correct
66 Correct 172 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 2808 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 2584 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 3 ms 2648 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 3 ms 2652 KB Output is correct
13 Correct 3 ms 2652 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
15 Correct 3 ms 2648 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2672 KB Output is correct
21 Correct 9 ms 2648 KB Output is correct
22 Correct 12 ms 4700 KB Output is correct
23 Correct 7 ms 2652 KB Output is correct
24 Correct 17 ms 4700 KB Output is correct
25 Correct 18 ms 4784 KB Output is correct
26 Correct 20 ms 4796 KB Output is correct
27 Correct 20 ms 4788 KB Output is correct
28 Correct 20 ms 4700 KB Output is correct
29 Correct 20 ms 4696 KB Output is correct
30 Correct 20 ms 4784 KB Output is correct
31 Correct 20 ms 4696 KB Output is correct
32 Correct 20 ms 4700 KB Output is correct
33 Correct 22 ms 4788 KB Output is correct
34 Correct 19 ms 4700 KB Output is correct
35 Correct 19 ms 4696 KB Output is correct
36 Correct 20 ms 4700 KB Output is correct
37 Correct 75 ms 6812 KB Output is correct
38 Correct 78 ms 6744 KB Output is correct
39 Correct 110 ms 8872 KB Output is correct
40 Correct 135 ms 8876 KB Output is correct
41 Correct 128 ms 8796 KB Output is correct
42 Correct 121 ms 8868 KB Output is correct
43 Correct 115 ms 9044 KB Output is correct
44 Correct 118 ms 9144 KB Output is correct
45 Correct 121 ms 9040 KB Output is correct
46 Correct 126 ms 8796 KB Output is correct
47 Correct 119 ms 9040 KB Output is correct
48 Correct 117 ms 9044 KB Output is correct
49 Correct 112 ms 8864 KB Output is correct
50 Correct 117 ms 9040 KB Output is correct
51 Correct 116 ms 8868 KB Output is correct
52 Correct 141 ms 9044 KB Output is correct
53 Correct 169 ms 11092 KB Output is correct
54 Correct 234 ms 13396 KB Output is correct
55 Correct 241 ms 13584 KB Output is correct
56 Correct 177 ms 11120 KB Output is correct
57 Correct 248 ms 13808 KB Output is correct
58 Correct 230 ms 13232 KB Output is correct
59 Correct 236 ms 13360 KB Output is correct
60 Correct 212 ms 13140 KB Output is correct
61 Correct 236 ms 13524 KB Output is correct
62 Correct 204 ms 11312 KB Output is correct
63 Correct 204 ms 11476 KB Output is correct
64 Correct 197 ms 11476 KB Output is correct
65 Correct 176 ms 11088 KB Output is correct
66 Correct 172 ms 10844 KB Output is correct
67 Correct 303 ms 13376 KB Output is correct
68 Correct 425 ms 15956 KB Output is correct
69 Correct 517 ms 16852 KB Output is correct
70 Correct 482 ms 16596 KB Output is correct
71 Correct 482 ms 16460 KB Output is correct
72 Correct 435 ms 15876 KB Output is correct
73 Correct 430 ms 15848 KB Output is correct
74 Correct 534 ms 17228 KB Output is correct
75 Correct 502 ms 16612 KB Output is correct
76 Correct 522 ms 17032 KB Output is correct
77 Correct 554 ms 17104 KB Output is correct