Submission #548776

# Submission time Handle Problem Language Result Execution time Memory
548776 2022-04-14T11:49:45 Z krit3379 Bootfall (IZhO17_bootfall) C++17
100 / 100
144 ms 4108 KB
#include<bits/stdc++.h>
using namespace std;
#define N 251000

int a[505],cnt[N],odd,even,sum;
vector<int> ans;
bitset<N> dp;

void sol(int l,int r,bitset<N> cur){
    if(l==r){
        for(int i=odd?1:2,val=sum-a[l];i<N;i+=2){
            if(val-i>=0&&cur[(val-i)/2])cnt[i]++;
        }
        return ;
    }
    int mid=(l+r)/2;
    bitset<N> dl=cur,dr=cur;
    for(int i=l;i<=mid;i++)dr|=dr<<a[i];
    for(int i=mid+1;i<=r;i++)dl|=dl<<a[i];
    sol(l,mid,dl),sol(mid+1,r,dr);
}

int main(){
    int n,i;
    scanf("%d",&n);
    dp=1;
    for(i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i],(a[i]%2)?odd++:even++,dp|=dp<<a[i];
    if((odd&&even)||(odd&&n%2)||!dp[sum/2]){printf("0");return 0;}
    dp=1;
    sol(1,n,dp);
    for(i=1;i<N;i++)if(cnt[i]==n)ans.push_back(i);
    printf("%d\n",ans.size());
    for(auto x:ans)printf("%d ",x);
    return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:32:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   32 |     printf("%d\n",ans.size());
      |             ~^    ~~~~~~~~~~
      |              |            |
      |              int          std::vector<int>::size_type {aka long unsigned int}
      |             %ld
bootfall.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
bootfall.cpp:27:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     for(i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i],(a[i]%2)?odd++:even++,dp|=dp<<a[i];
      |                      ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 3 ms 1108 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 3 ms 1108 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 6 ms 1236 KB Output is correct
11 Correct 6 ms 1236 KB Output is correct
12 Correct 6 ms 1316 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 5 ms 1236 KB Output is correct
15 Correct 6 ms 1268 KB Output is correct
16 Correct 5 ms 1268 KB Output is correct
17 Correct 4 ms 1236 KB Output is correct
18 Correct 5 ms 1324 KB Output is correct
19 Correct 5 ms 1312 KB Output is correct
20 Correct 6 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 3 ms 1108 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 6 ms 1236 KB Output is correct
11 Correct 6 ms 1236 KB Output is correct
12 Correct 6 ms 1316 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 5 ms 1236 KB Output is correct
15 Correct 6 ms 1268 KB Output is correct
16 Correct 5 ms 1268 KB Output is correct
17 Correct 4 ms 1236 KB Output is correct
18 Correct 5 ms 1324 KB Output is correct
19 Correct 5 ms 1312 KB Output is correct
20 Correct 6 ms 1236 KB Output is correct
21 Correct 11 ms 1492 KB Output is correct
22 Correct 13 ms 1620 KB Output is correct
23 Correct 9 ms 1472 KB Output is correct
24 Correct 16 ms 1640 KB Output is correct
25 Correct 16 ms 1620 KB Output is correct
26 Correct 17 ms 1664 KB Output is correct
27 Correct 16 ms 1656 KB Output is correct
28 Correct 18 ms 1664 KB Output is correct
29 Correct 17 ms 1656 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 17 ms 1648 KB Output is correct
32 Correct 16 ms 1620 KB Output is correct
33 Correct 16 ms 1660 KB Output is correct
34 Correct 17 ms 1656 KB Output is correct
35 Correct 18 ms 1620 KB Output is correct
36 Correct 16 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 3 ms 1108 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 6 ms 1236 KB Output is correct
11 Correct 6 ms 1236 KB Output is correct
12 Correct 6 ms 1316 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 5 ms 1236 KB Output is correct
15 Correct 6 ms 1268 KB Output is correct
16 Correct 5 ms 1268 KB Output is correct
17 Correct 4 ms 1236 KB Output is correct
18 Correct 5 ms 1324 KB Output is correct
19 Correct 5 ms 1312 KB Output is correct
20 Correct 6 ms 1236 KB Output is correct
21 Correct 11 ms 1492 KB Output is correct
22 Correct 13 ms 1620 KB Output is correct
23 Correct 9 ms 1472 KB Output is correct
24 Correct 16 ms 1640 KB Output is correct
25 Correct 16 ms 1620 KB Output is correct
26 Correct 17 ms 1664 KB Output is correct
27 Correct 16 ms 1656 KB Output is correct
28 Correct 18 ms 1664 KB Output is correct
29 Correct 17 ms 1656 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 17 ms 1648 KB Output is correct
32 Correct 16 ms 1620 KB Output is correct
33 Correct 16 ms 1660 KB Output is correct
34 Correct 17 ms 1656 KB Output is correct
35 Correct 18 ms 1620 KB Output is correct
36 Correct 16 ms 1620 KB Output is correct
37 Correct 34 ms 1972 KB Output is correct
38 Correct 34 ms 1940 KB Output is correct
39 Correct 45 ms 2004 KB Output is correct
40 Correct 46 ms 2164 KB Output is correct
41 Correct 47 ms 2188 KB Output is correct
42 Correct 43 ms 2012 KB Output is correct
43 Correct 44 ms 2260 KB Output is correct
44 Correct 48 ms 2356 KB Output is correct
45 Correct 45 ms 2364 KB Output is correct
46 Correct 48 ms 2004 KB Output is correct
47 Correct 42 ms 2024 KB Output is correct
48 Correct 53 ms 2252 KB Output is correct
49 Correct 47 ms 2004 KB Output is correct
50 Correct 43 ms 2008 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
52 Correct 55 ms 2580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 3 ms 1108 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 6 ms 1236 KB Output is correct
11 Correct 6 ms 1236 KB Output is correct
12 Correct 6 ms 1316 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 5 ms 1236 KB Output is correct
15 Correct 6 ms 1268 KB Output is correct
16 Correct 5 ms 1268 KB Output is correct
17 Correct 4 ms 1236 KB Output is correct
18 Correct 5 ms 1324 KB Output is correct
19 Correct 5 ms 1312 KB Output is correct
20 Correct 6 ms 1236 KB Output is correct
21 Correct 11 ms 1492 KB Output is correct
22 Correct 13 ms 1620 KB Output is correct
23 Correct 9 ms 1472 KB Output is correct
24 Correct 16 ms 1640 KB Output is correct
25 Correct 16 ms 1620 KB Output is correct
26 Correct 17 ms 1664 KB Output is correct
27 Correct 16 ms 1656 KB Output is correct
28 Correct 18 ms 1664 KB Output is correct
29 Correct 17 ms 1656 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 17 ms 1648 KB Output is correct
32 Correct 16 ms 1620 KB Output is correct
33 Correct 16 ms 1660 KB Output is correct
34 Correct 17 ms 1656 KB Output is correct
35 Correct 18 ms 1620 KB Output is correct
36 Correct 16 ms 1620 KB Output is correct
37 Correct 34 ms 1972 KB Output is correct
38 Correct 34 ms 1940 KB Output is correct
39 Correct 45 ms 2004 KB Output is correct
40 Correct 46 ms 2164 KB Output is correct
41 Correct 47 ms 2188 KB Output is correct
42 Correct 43 ms 2012 KB Output is correct
43 Correct 44 ms 2260 KB Output is correct
44 Correct 48 ms 2356 KB Output is correct
45 Correct 45 ms 2364 KB Output is correct
46 Correct 48 ms 2004 KB Output is correct
47 Correct 42 ms 2024 KB Output is correct
48 Correct 53 ms 2252 KB Output is correct
49 Correct 47 ms 2004 KB Output is correct
50 Correct 43 ms 2008 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
52 Correct 55 ms 2580 KB Output is correct
53 Correct 57 ms 2348 KB Output is correct
54 Correct 62 ms 2512 KB Output is correct
55 Correct 75 ms 2864 KB Output is correct
56 Correct 58 ms 2524 KB Output is correct
57 Correct 70 ms 3004 KB Output is correct
58 Correct 66 ms 2524 KB Output is correct
59 Correct 70 ms 2680 KB Output is correct
60 Correct 3 ms 372 KB Output is correct
61 Correct 68 ms 2752 KB Output is correct
62 Correct 63 ms 2788 KB Output is correct
63 Correct 72 ms 2824 KB Output is correct
64 Correct 66 ms 2820 KB Output is correct
65 Correct 60 ms 2108 KB Output is correct
66 Correct 72 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 3 ms 1108 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 6 ms 1236 KB Output is correct
11 Correct 6 ms 1236 KB Output is correct
12 Correct 6 ms 1316 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 5 ms 1236 KB Output is correct
15 Correct 6 ms 1268 KB Output is correct
16 Correct 5 ms 1268 KB Output is correct
17 Correct 4 ms 1236 KB Output is correct
18 Correct 5 ms 1324 KB Output is correct
19 Correct 5 ms 1312 KB Output is correct
20 Correct 6 ms 1236 KB Output is correct
21 Correct 11 ms 1492 KB Output is correct
22 Correct 13 ms 1620 KB Output is correct
23 Correct 9 ms 1472 KB Output is correct
24 Correct 16 ms 1640 KB Output is correct
25 Correct 16 ms 1620 KB Output is correct
26 Correct 17 ms 1664 KB Output is correct
27 Correct 16 ms 1656 KB Output is correct
28 Correct 18 ms 1664 KB Output is correct
29 Correct 17 ms 1656 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 17 ms 1648 KB Output is correct
32 Correct 16 ms 1620 KB Output is correct
33 Correct 16 ms 1660 KB Output is correct
34 Correct 17 ms 1656 KB Output is correct
35 Correct 18 ms 1620 KB Output is correct
36 Correct 16 ms 1620 KB Output is correct
37 Correct 34 ms 1972 KB Output is correct
38 Correct 34 ms 1940 KB Output is correct
39 Correct 45 ms 2004 KB Output is correct
40 Correct 46 ms 2164 KB Output is correct
41 Correct 47 ms 2188 KB Output is correct
42 Correct 43 ms 2012 KB Output is correct
43 Correct 44 ms 2260 KB Output is correct
44 Correct 48 ms 2356 KB Output is correct
45 Correct 45 ms 2364 KB Output is correct
46 Correct 48 ms 2004 KB Output is correct
47 Correct 42 ms 2024 KB Output is correct
48 Correct 53 ms 2252 KB Output is correct
49 Correct 47 ms 2004 KB Output is correct
50 Correct 43 ms 2008 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
52 Correct 55 ms 2580 KB Output is correct
53 Correct 57 ms 2348 KB Output is correct
54 Correct 62 ms 2512 KB Output is correct
55 Correct 75 ms 2864 KB Output is correct
56 Correct 58 ms 2524 KB Output is correct
57 Correct 70 ms 3004 KB Output is correct
58 Correct 66 ms 2524 KB Output is correct
59 Correct 70 ms 2680 KB Output is correct
60 Correct 3 ms 372 KB Output is correct
61 Correct 68 ms 2752 KB Output is correct
62 Correct 63 ms 2788 KB Output is correct
63 Correct 72 ms 2824 KB Output is correct
64 Correct 66 ms 2820 KB Output is correct
65 Correct 60 ms 2108 KB Output is correct
66 Correct 72 ms 2132 KB Output is correct
67 Correct 99 ms 2736 KB Output is correct
68 Correct 6 ms 340 KB Output is correct
69 Correct 124 ms 3880 KB Output is correct
70 Correct 115 ms 3176 KB Output is correct
71 Correct 104 ms 3096 KB Output is correct
72 Correct 5 ms 340 KB Output is correct
73 Correct 9 ms 340 KB Output is correct
74 Correct 123 ms 3984 KB Output is correct
75 Correct 113 ms 3488 KB Output is correct
76 Correct 135 ms 4012 KB Output is correct
77 Correct 144 ms 4108 KB Output is correct