Submission #1055039

# Submission time Handle Problem Language Result Execution time Memory
1055039 2024-08-12T14:11:33 Z Khanhcsp2 Bootfall (IZhO17_bootfall) C++14
100 / 100
252 ms 33620 KB
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
#define el '\n'
#define fi first
#define sc second
//#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e9+7;
const int N=511;
int n, a[N], sum;
bitset<N*N> bs, cur, s1, s2, pf1[N], pf2[N];
void sol()
{
    cin >> n;
    for(int i=1;i<=n;i++) cin >> a[i];
    bs&=0;
    bs[0]=1;
    for(int i=1;i<=n;i++)
    {
        bs|=bs<<(a[i]);
        sum+=a[i];
    }
    if(sum&1 || bs[sum/2]==0)
    {
        cout << 0 << el;
        return;
    }
    pf1[0][0]=1;
    pf2[n+1][0]=1;
    for(int i=1;i<=n;i++) pf1[i]=pf1[i-1]|(pf1[i-1]<<a[i]);
    for(int i=n;i>=1;i--) pf2[i]=pf2[i+1]|(pf2[i+1]<<a[i]);
    int ch1=1, ch2=1;
    s1.set();
    s2.set();
    s2[0]=0;
    for(int i=1;i<=n;i++)
    {
        if(i<=n/2)
        {
            cur=pf2[i+1];
            for(int j=i-1;j>=1;j--) cur|=(cur<<(a[j]));
        }
        else
        {
            cur=pf1[i-1];
            for(int j=i+1;j<=n;j++) cur|=(cur<<(a[j]));
        }
        int ss=sum-a[i];
        if(ss%2==0)
        {
            s2&=(cur>>(ss/2));
            if(ch1)
            {
               s1&=0;
               ch1=0;
            }
        }
        else
        {
            s1&=(cur>>(ss/2+1));
            if(ch2)
            {
                s2&=0;
                ch2=0;
            }
        }
    }
    cout << s1.count()+s2.count() << el;
    for(int i=0;i<N*N;i++)
    {
        if(s2[i]) cout << i*2 << el;
        if(s1[i]) cout << i*2+1 << el;
    }
}
signed main()
{
//    freopen("divisor.INP", "r", stdin);
//    freopen("divisor.OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    //cin >> t;
    while(t--)
    {
        sol();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6760 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6760 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 6 ms 6936 KB Output is correct
22 Correct 7 ms 10844 KB Output is correct
23 Correct 4 ms 6748 KB Output is correct
24 Correct 11 ms 10844 KB Output is correct
25 Correct 11 ms 10844 KB Output is correct
26 Correct 12 ms 11044 KB Output is correct
27 Correct 12 ms 10844 KB Output is correct
28 Correct 12 ms 10840 KB Output is correct
29 Correct 12 ms 10844 KB Output is correct
30 Correct 12 ms 10844 KB Output is correct
31 Correct 16 ms 11100 KB Output is correct
32 Correct 14 ms 11048 KB Output is correct
33 Correct 12 ms 10844 KB Output is correct
34 Correct 12 ms 11048 KB Output is correct
35 Correct 12 ms 10808 KB Output is correct
36 Correct 12 ms 11048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6760 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 6 ms 6936 KB Output is correct
22 Correct 7 ms 10844 KB Output is correct
23 Correct 4 ms 6748 KB Output is correct
24 Correct 11 ms 10844 KB Output is correct
25 Correct 11 ms 10844 KB Output is correct
26 Correct 12 ms 11044 KB Output is correct
27 Correct 12 ms 10844 KB Output is correct
28 Correct 12 ms 10840 KB Output is correct
29 Correct 12 ms 10844 KB Output is correct
30 Correct 12 ms 10844 KB Output is correct
31 Correct 16 ms 11100 KB Output is correct
32 Correct 14 ms 11048 KB Output is correct
33 Correct 12 ms 10844 KB Output is correct
34 Correct 12 ms 11048 KB Output is correct
35 Correct 12 ms 10808 KB Output is correct
36 Correct 12 ms 11048 KB Output is correct
37 Correct 42 ms 19244 KB Output is correct
38 Correct 42 ms 19284 KB Output is correct
39 Correct 61 ms 19036 KB Output is correct
40 Correct 72 ms 23380 KB Output is correct
41 Correct 74 ms 23288 KB Output is correct
42 Correct 63 ms 19236 KB Output is correct
43 Correct 61 ms 19284 KB Output is correct
44 Correct 64 ms 19280 KB Output is correct
45 Correct 63 ms 19288 KB Output is correct
46 Correct 81 ms 23128 KB Output is correct
47 Correct 63 ms 19280 KB Output is correct
48 Correct 65 ms 19284 KB Output is correct
49 Correct 64 ms 19228 KB Output is correct
50 Correct 64 ms 19248 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 73 ms 23380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6760 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 6 ms 6936 KB Output is correct
22 Correct 7 ms 10844 KB Output is correct
23 Correct 4 ms 6748 KB Output is correct
24 Correct 11 ms 10844 KB Output is correct
25 Correct 11 ms 10844 KB Output is correct
26 Correct 12 ms 11044 KB Output is correct
27 Correct 12 ms 10844 KB Output is correct
28 Correct 12 ms 10840 KB Output is correct
29 Correct 12 ms 10844 KB Output is correct
30 Correct 12 ms 10844 KB Output is correct
31 Correct 16 ms 11100 KB Output is correct
32 Correct 14 ms 11048 KB Output is correct
33 Correct 12 ms 10844 KB Output is correct
34 Correct 12 ms 11048 KB Output is correct
35 Correct 12 ms 10808 KB Output is correct
36 Correct 12 ms 11048 KB Output is correct
37 Correct 42 ms 19244 KB Output is correct
38 Correct 42 ms 19284 KB Output is correct
39 Correct 61 ms 19036 KB Output is correct
40 Correct 72 ms 23380 KB Output is correct
41 Correct 74 ms 23288 KB Output is correct
42 Correct 63 ms 19236 KB Output is correct
43 Correct 61 ms 19284 KB Output is correct
44 Correct 64 ms 19280 KB Output is correct
45 Correct 63 ms 19288 KB Output is correct
46 Correct 81 ms 23128 KB Output is correct
47 Correct 63 ms 19280 KB Output is correct
48 Correct 65 ms 19284 KB Output is correct
49 Correct 64 ms 19228 KB Output is correct
50 Correct 64 ms 19248 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 73 ms 23380 KB Output is correct
53 Correct 106 ms 23332 KB Output is correct
54 Correct 134 ms 27452 KB Output is correct
55 Correct 128 ms 27692 KB Output is correct
56 Correct 95 ms 23340 KB Output is correct
57 Correct 124 ms 27704 KB Output is correct
58 Correct 121 ms 27436 KB Output is correct
59 Correct 121 ms 27476 KB Output is correct
60 Correct 2 ms 344 KB Output is correct
61 Correct 123 ms 27476 KB Output is correct
62 Correct 104 ms 23584 KB Output is correct
63 Correct 103 ms 23380 KB Output is correct
64 Correct 100 ms 23588 KB Output is correct
65 Correct 97 ms 23128 KB Output is correct
66 Correct 94 ms 23328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6760 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 6 ms 6936 KB Output is correct
22 Correct 7 ms 10844 KB Output is correct
23 Correct 4 ms 6748 KB Output is correct
24 Correct 11 ms 10844 KB Output is correct
25 Correct 11 ms 10844 KB Output is correct
26 Correct 12 ms 11044 KB Output is correct
27 Correct 12 ms 10844 KB Output is correct
28 Correct 12 ms 10840 KB Output is correct
29 Correct 12 ms 10844 KB Output is correct
30 Correct 12 ms 10844 KB Output is correct
31 Correct 16 ms 11100 KB Output is correct
32 Correct 14 ms 11048 KB Output is correct
33 Correct 12 ms 10844 KB Output is correct
34 Correct 12 ms 11048 KB Output is correct
35 Correct 12 ms 10808 KB Output is correct
36 Correct 12 ms 11048 KB Output is correct
37 Correct 42 ms 19244 KB Output is correct
38 Correct 42 ms 19284 KB Output is correct
39 Correct 61 ms 19036 KB Output is correct
40 Correct 72 ms 23380 KB Output is correct
41 Correct 74 ms 23288 KB Output is correct
42 Correct 63 ms 19236 KB Output is correct
43 Correct 61 ms 19284 KB Output is correct
44 Correct 64 ms 19280 KB Output is correct
45 Correct 63 ms 19288 KB Output is correct
46 Correct 81 ms 23128 KB Output is correct
47 Correct 63 ms 19280 KB Output is correct
48 Correct 65 ms 19284 KB Output is correct
49 Correct 64 ms 19228 KB Output is correct
50 Correct 64 ms 19248 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 73 ms 23380 KB Output is correct
53 Correct 106 ms 23332 KB Output is correct
54 Correct 134 ms 27452 KB Output is correct
55 Correct 128 ms 27692 KB Output is correct
56 Correct 95 ms 23340 KB Output is correct
57 Correct 124 ms 27704 KB Output is correct
58 Correct 121 ms 27436 KB Output is correct
59 Correct 121 ms 27476 KB Output is correct
60 Correct 2 ms 344 KB Output is correct
61 Correct 123 ms 27476 KB Output is correct
62 Correct 104 ms 23584 KB Output is correct
63 Correct 103 ms 23380 KB Output is correct
64 Correct 100 ms 23588 KB Output is correct
65 Correct 97 ms 23128 KB Output is correct
66 Correct 94 ms 23328 KB Output is correct
67 Correct 155 ms 31552 KB Output is correct
68 Correct 3 ms 344 KB Output is correct
69 Correct 244 ms 33436 KB Output is correct
70 Correct 248 ms 33108 KB Output is correct
71 Correct 240 ms 33108 KB Output is correct
72 Correct 249 ms 32928 KB Output is correct
73 Correct 235 ms 32856 KB Output is correct
74 Correct 252 ms 33364 KB Output is correct
75 Correct 250 ms 33360 KB Output is correct
76 Correct 250 ms 33360 KB Output is correct
77 Correct 244 ms 33620 KB Output is correct