Submission #393808

# Submission time Handle Problem Language Result Execution time Memory
393808 2021-04-24T14:32:09 Z vanic Bootfall (IZhO17_bootfall) C++14
100 / 100
569 ms 16836 KB
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <vector>

using namespace std;

const int maxn=505, Log=9, pot=(1<<Log);

int n;
int a[maxn];
bitset < maxn*maxn > dp[maxn];
bitset < maxn*maxn > sol;
vector < int > t[pot*2];
int tren;
int sum;
int sumuk;

void probaj(){
	dp[tren]=(dp[tren-1]>>((sum+2)/2));
	sol&=dp[tren];
}

void dodaj(int x){
	sum+=x;
	dp[tren]=dp[tren-1]|(dp[tren-1]<<x);
	tren++;
}

void update(int L, int D, int x, int l, int d, int val){
	if(L>=l && D<=d){
		t[x].push_back(val);
		return;
	}
	if((L+D)/2>=l){
		update(L, (L+D)/2, x*2, l, d, val);
	}
	if((L+D)/2+1<=d){
		update((L+D)/2+1, D, x*2+1, l, d, val);
	}
}


void query(int x){
//	cout << "na " << x << endl;
	for(int i=0; i<(int)t[x].size(); i++){
//		cout << "dodajem " << t[x][i] << endl;
		dodaj(t[x][i]);
	}
	if(x>=pot){
		if(x-pot<n){
			probaj();
		}
	}
	else{
		query(x*2);
		query(x*2+1);
	}
	for(int i=0; i<(int)t[x].size(); i++){
		sum-=t[x][i];
	}
	tren-=t[x].size();
}

void precompute(){
	for(int i=0; i<maxn*maxn; i++){
		sol[i]=1;
	}
}

int main(){
	scanf("%d", &n);
	int par=0, nep=0;
	precompute();
	for(int i=0; i<n; i++){
		scanf("%d", &a[i]);
		sumuk+=a[i];
		if(a[i]&1){
			nep++;
		}
		else{
			par++;
		}
	}
	if(par && nep){
		printf("0\n");
		return 0;
	}
	for(int i=0; i<n; i++){
		if(i){
			update(0, pot-1, 1, 0, i-1, a[i]);
		}
		if(i<n-1){
			update(0, pot-1, 1, i+1, pot-1, a[i]);
		}
	}
	dp[0][0]=1;
	for(int i=0; i<n; i++){
		for(int j=sumuk; j>=a[i]; j--){
			dp[0][j]=dp[0][j]|dp[0][j-a[i]];
		}
	}
	if((sumuk&1) || !dp[0][sumuk/2]){
		printf("0\n");
		return 0;
	}
	dp[0].reset();
	dp[0][0]=1;
	tren=1;
	query(1);
	printf("%d\n", (int)sol.count());
	for(int i=0; i<maxn*maxn; i++){
		if(sol[i]){
			if(par){
				printf("%d " , (i+1)*2);
			}
			else{
				printf("%d " , (i+1)*2-1);
			}
		}
	}
	printf("\n");
	return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
bootfall.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   78 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 7 ms 1348 KB Output is correct
11 Correct 7 ms 1356 KB Output is correct
12 Correct 6 ms 1356 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 5 ms 1228 KB Output is correct
15 Correct 5 ms 1228 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 4 ms 972 KB Output is correct
18 Correct 5 ms 1100 KB Output is correct
19 Correct 5 ms 1228 KB Output is correct
20 Correct 6 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 7 ms 1348 KB Output is correct
11 Correct 7 ms 1356 KB Output is correct
12 Correct 6 ms 1356 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 5 ms 1228 KB Output is correct
15 Correct 5 ms 1228 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 4 ms 972 KB Output is correct
18 Correct 5 ms 1100 KB Output is correct
19 Correct 5 ms 1228 KB Output is correct
20 Correct 6 ms 1356 KB Output is correct
21 Correct 12 ms 2448 KB Output is correct
22 Correct 13 ms 2764 KB Output is correct
23 Correct 9 ms 1996 KB Output is correct
24 Correct 18 ms 3392 KB Output is correct
25 Correct 19 ms 3392 KB Output is correct
26 Correct 25 ms 3532 KB Output is correct
27 Correct 20 ms 3532 KB Output is correct
28 Correct 20 ms 3532 KB Output is correct
29 Correct 20 ms 3532 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 19 ms 3516 KB Output is correct
32 Correct 18 ms 3532 KB Output is correct
33 Correct 19 ms 3532 KB Output is correct
34 Correct 20 ms 3532 KB Output is correct
35 Correct 23 ms 3576 KB Output is correct
36 Correct 20 ms 3532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 7 ms 1348 KB Output is correct
11 Correct 7 ms 1356 KB Output is correct
12 Correct 6 ms 1356 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 5 ms 1228 KB Output is correct
15 Correct 5 ms 1228 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 4 ms 972 KB Output is correct
18 Correct 5 ms 1100 KB Output is correct
19 Correct 5 ms 1228 KB Output is correct
20 Correct 6 ms 1356 KB Output is correct
21 Correct 12 ms 2448 KB Output is correct
22 Correct 13 ms 2764 KB Output is correct
23 Correct 9 ms 1996 KB Output is correct
24 Correct 18 ms 3392 KB Output is correct
25 Correct 19 ms 3392 KB Output is correct
26 Correct 25 ms 3532 KB Output is correct
27 Correct 20 ms 3532 KB Output is correct
28 Correct 20 ms 3532 KB Output is correct
29 Correct 20 ms 3532 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 19 ms 3516 KB Output is correct
32 Correct 18 ms 3532 KB Output is correct
33 Correct 19 ms 3532 KB Output is correct
34 Correct 20 ms 3532 KB Output is correct
35 Correct 23 ms 3576 KB Output is correct
36 Correct 20 ms 3532 KB Output is correct
37 Correct 47 ms 6648 KB Output is correct
38 Correct 47 ms 6652 KB Output is correct
39 Correct 98 ms 8188 KB Output is correct
40 Correct 76 ms 8952 KB Output is correct
41 Correct 119 ms 8832 KB Output is correct
42 Correct 72 ms 8260 KB Output is correct
43 Correct 93 ms 8132 KB Output is correct
44 Correct 93 ms 8312 KB Output is correct
45 Correct 95 ms 8312 KB Output is correct
46 Correct 73 ms 8960 KB Output is correct
47 Correct 79 ms 8248 KB Output is correct
48 Correct 99 ms 8316 KB Output is correct
49 Correct 104 ms 8252 KB Output is correct
50 Correct 83 ms 8300 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 117 ms 9028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 7 ms 1348 KB Output is correct
11 Correct 7 ms 1356 KB Output is correct
12 Correct 6 ms 1356 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 5 ms 1228 KB Output is correct
15 Correct 5 ms 1228 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 4 ms 972 KB Output is correct
18 Correct 5 ms 1100 KB Output is correct
19 Correct 5 ms 1228 KB Output is correct
20 Correct 6 ms 1356 KB Output is correct
21 Correct 12 ms 2448 KB Output is correct
22 Correct 13 ms 2764 KB Output is correct
23 Correct 9 ms 1996 KB Output is correct
24 Correct 18 ms 3392 KB Output is correct
25 Correct 19 ms 3392 KB Output is correct
26 Correct 25 ms 3532 KB Output is correct
27 Correct 20 ms 3532 KB Output is correct
28 Correct 20 ms 3532 KB Output is correct
29 Correct 20 ms 3532 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 19 ms 3516 KB Output is correct
32 Correct 18 ms 3532 KB Output is correct
33 Correct 19 ms 3532 KB Output is correct
34 Correct 20 ms 3532 KB Output is correct
35 Correct 23 ms 3576 KB Output is correct
36 Correct 20 ms 3532 KB Output is correct
37 Correct 47 ms 6648 KB Output is correct
38 Correct 47 ms 6652 KB Output is correct
39 Correct 98 ms 8188 KB Output is correct
40 Correct 76 ms 8952 KB Output is correct
41 Correct 119 ms 8832 KB Output is correct
42 Correct 72 ms 8260 KB Output is correct
43 Correct 93 ms 8132 KB Output is correct
44 Correct 93 ms 8312 KB Output is correct
45 Correct 95 ms 8312 KB Output is correct
46 Correct 73 ms 8960 KB Output is correct
47 Correct 79 ms 8248 KB Output is correct
48 Correct 99 ms 8316 KB Output is correct
49 Correct 104 ms 8252 KB Output is correct
50 Correct 83 ms 8300 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 117 ms 9028 KB Output is correct
53 Correct 119 ms 9852 KB Output is correct
54 Correct 131 ms 11512 KB Output is correct
55 Correct 209 ms 11588 KB Output is correct
56 Correct 114 ms 10096 KB Output is correct
57 Correct 216 ms 11632 KB Output is correct
58 Correct 137 ms 11524 KB Output is correct
59 Correct 165 ms 11512 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 173 ms 11528 KB Output is correct
62 Correct 169 ms 10704 KB Output is correct
63 Correct 209 ms 10764 KB Output is correct
64 Correct 179 ms 10564 KB Output is correct
65 Correct 116 ms 10436 KB Output is correct
66 Correct 114 ms 10124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 7 ms 1348 KB Output is correct
11 Correct 7 ms 1356 KB Output is correct
12 Correct 6 ms 1356 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 5 ms 1228 KB Output is correct
15 Correct 5 ms 1228 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 4 ms 972 KB Output is correct
18 Correct 5 ms 1100 KB Output is correct
19 Correct 5 ms 1228 KB Output is correct
20 Correct 6 ms 1356 KB Output is correct
21 Correct 12 ms 2448 KB Output is correct
22 Correct 13 ms 2764 KB Output is correct
23 Correct 9 ms 1996 KB Output is correct
24 Correct 18 ms 3392 KB Output is correct
25 Correct 19 ms 3392 KB Output is correct
26 Correct 25 ms 3532 KB Output is correct
27 Correct 20 ms 3532 KB Output is correct
28 Correct 20 ms 3532 KB Output is correct
29 Correct 20 ms 3532 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 19 ms 3516 KB Output is correct
32 Correct 18 ms 3532 KB Output is correct
33 Correct 19 ms 3532 KB Output is correct
34 Correct 20 ms 3532 KB Output is correct
35 Correct 23 ms 3576 KB Output is correct
36 Correct 20 ms 3532 KB Output is correct
37 Correct 47 ms 6648 KB Output is correct
38 Correct 47 ms 6652 KB Output is correct
39 Correct 98 ms 8188 KB Output is correct
40 Correct 76 ms 8952 KB Output is correct
41 Correct 119 ms 8832 KB Output is correct
42 Correct 72 ms 8260 KB Output is correct
43 Correct 93 ms 8132 KB Output is correct
44 Correct 93 ms 8312 KB Output is correct
45 Correct 95 ms 8312 KB Output is correct
46 Correct 73 ms 8960 KB Output is correct
47 Correct 79 ms 8248 KB Output is correct
48 Correct 99 ms 8316 KB Output is correct
49 Correct 104 ms 8252 KB Output is correct
50 Correct 83 ms 8300 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 117 ms 9028 KB Output is correct
53 Correct 119 ms 9852 KB Output is correct
54 Correct 131 ms 11512 KB Output is correct
55 Correct 209 ms 11588 KB Output is correct
56 Correct 114 ms 10096 KB Output is correct
57 Correct 216 ms 11632 KB Output is correct
58 Correct 137 ms 11524 KB Output is correct
59 Correct 165 ms 11512 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 173 ms 11528 KB Output is correct
62 Correct 169 ms 10704 KB Output is correct
63 Correct 209 ms 10764 KB Output is correct
64 Correct 179 ms 10564 KB Output is correct
65 Correct 116 ms 10436 KB Output is correct
66 Correct 114 ms 10124 KB Output is correct
67 Correct 203 ms 13124 KB Output is correct
68 Correct 249 ms 452 KB Output is correct
69 Correct 496 ms 16676 KB Output is correct
70 Correct 333 ms 16400 KB Output is correct
71 Correct 327 ms 16336 KB Output is correct
72 Correct 2 ms 324 KB Output is correct
73 Correct 1 ms 332 KB Output is correct
74 Correct 511 ms 16668 KB Output is correct
75 Correct 418 ms 16564 KB Output is correct
76 Correct 569 ms 16836 KB Output is correct
77 Correct 561 ms 16708 KB Output is correct