Submission #393463

# Submission time Handle Problem Language Result Execution time Memory
393463 2021-04-23T14:03:12 Z vanic Bootfall (IZhO17_bootfall) C++14
44 / 100
1000 ms 6628 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;
	for(int i=sumuk; i>-1; --i){
		if(i>=x){
			dp[tren][i]=dp[tren-1][i-x]|dp[tren-1][i];
		}
		else{
			dp[tren][i]=dp[tren-1][i];
		}
	}
	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:81:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   81 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
bootfall.cpp:85:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   85 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 2 ms 584 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 4 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 2 ms 584 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 4 ms 588 KB Output is correct
21 Correct 10 ms 764 KB Output is correct
22 Correct 12 ms 812 KB Output is correct
23 Correct 7 ms 572 KB Output is correct
24 Correct 19 ms 924 KB Output is correct
25 Correct 34 ms 964 KB Output is correct
26 Correct 39 ms 1012 KB Output is correct
27 Correct 35 ms 900 KB Output is correct
28 Correct 38 ms 1000 KB Output is correct
29 Correct 38 ms 1016 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 30 ms 976 KB Output is correct
32 Correct 20 ms 844 KB Output is correct
33 Correct 40 ms 996 KB Output is correct
34 Correct 39 ms 996 KB Output is correct
35 Correct 38 ms 920 KB Output is correct
36 Correct 20 ms 892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 2 ms 584 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 4 ms 588 KB Output is correct
21 Correct 10 ms 764 KB Output is correct
22 Correct 12 ms 812 KB Output is correct
23 Correct 7 ms 572 KB Output is correct
24 Correct 19 ms 924 KB Output is correct
25 Correct 34 ms 964 KB Output is correct
26 Correct 39 ms 1012 KB Output is correct
27 Correct 35 ms 900 KB Output is correct
28 Correct 38 ms 1000 KB Output is correct
29 Correct 38 ms 1016 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 30 ms 976 KB Output is correct
32 Correct 20 ms 844 KB Output is correct
33 Correct 40 ms 996 KB Output is correct
34 Correct 39 ms 996 KB Output is correct
35 Correct 38 ms 920 KB Output is correct
36 Correct 20 ms 892 KB Output is correct
37 Correct 152 ms 1752 KB Output is correct
38 Correct 151 ms 1764 KB Output is correct
39 Correct 562 ms 3396 KB Output is correct
40 Correct 341 ms 2756 KB Output is correct
41 Correct 740 ms 3976 KB Output is correct
42 Correct 277 ms 2372 KB Output is correct
43 Correct 498 ms 3344 KB Output is correct
44 Correct 521 ms 3308 KB Output is correct
45 Correct 525 ms 3440 KB Output is correct
46 Correct 323 ms 2632 KB Output is correct
47 Correct 311 ms 2560 KB Output is correct
48 Correct 578 ms 3396 KB Output is correct
49 Correct 564 ms 3480 KB Output is correct
50 Correct 311 ms 2636 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 699 ms 4016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 2 ms 584 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 4 ms 588 KB Output is correct
21 Correct 10 ms 764 KB Output is correct
22 Correct 12 ms 812 KB Output is correct
23 Correct 7 ms 572 KB Output is correct
24 Correct 19 ms 924 KB Output is correct
25 Correct 34 ms 964 KB Output is correct
26 Correct 39 ms 1012 KB Output is correct
27 Correct 35 ms 900 KB Output is correct
28 Correct 38 ms 1000 KB Output is correct
29 Correct 38 ms 1016 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 30 ms 976 KB Output is correct
32 Correct 20 ms 844 KB Output is correct
33 Correct 40 ms 996 KB Output is correct
34 Correct 39 ms 996 KB Output is correct
35 Correct 38 ms 920 KB Output is correct
36 Correct 20 ms 892 KB Output is correct
37 Correct 152 ms 1752 KB Output is correct
38 Correct 151 ms 1764 KB Output is correct
39 Correct 562 ms 3396 KB Output is correct
40 Correct 341 ms 2756 KB Output is correct
41 Correct 740 ms 3976 KB Output is correct
42 Correct 277 ms 2372 KB Output is correct
43 Correct 498 ms 3344 KB Output is correct
44 Correct 521 ms 3308 KB Output is correct
45 Correct 525 ms 3440 KB Output is correct
46 Correct 323 ms 2632 KB Output is correct
47 Correct 311 ms 2560 KB Output is correct
48 Correct 578 ms 3396 KB Output is correct
49 Correct 564 ms 3480 KB Output is correct
50 Correct 311 ms 2636 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 699 ms 4016 KB Output is correct
53 Correct 517 ms 3488 KB Output is correct
54 Correct 721 ms 4408 KB Output is correct
55 Execution timed out 1091 ms 6628 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 2 ms 584 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 4 ms 588 KB Output is correct
21 Correct 10 ms 764 KB Output is correct
22 Correct 12 ms 812 KB Output is correct
23 Correct 7 ms 572 KB Output is correct
24 Correct 19 ms 924 KB Output is correct
25 Correct 34 ms 964 KB Output is correct
26 Correct 39 ms 1012 KB Output is correct
27 Correct 35 ms 900 KB Output is correct
28 Correct 38 ms 1000 KB Output is correct
29 Correct 38 ms 1016 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 30 ms 976 KB Output is correct
32 Correct 20 ms 844 KB Output is correct
33 Correct 40 ms 996 KB Output is correct
34 Correct 39 ms 996 KB Output is correct
35 Correct 38 ms 920 KB Output is correct
36 Correct 20 ms 892 KB Output is correct
37 Correct 152 ms 1752 KB Output is correct
38 Correct 151 ms 1764 KB Output is correct
39 Correct 562 ms 3396 KB Output is correct
40 Correct 341 ms 2756 KB Output is correct
41 Correct 740 ms 3976 KB Output is correct
42 Correct 277 ms 2372 KB Output is correct
43 Correct 498 ms 3344 KB Output is correct
44 Correct 521 ms 3308 KB Output is correct
45 Correct 525 ms 3440 KB Output is correct
46 Correct 323 ms 2632 KB Output is correct
47 Correct 311 ms 2560 KB Output is correct
48 Correct 578 ms 3396 KB Output is correct
49 Correct 564 ms 3480 KB Output is correct
50 Correct 311 ms 2636 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 699 ms 4016 KB Output is correct
53 Correct 517 ms 3488 KB Output is correct
54 Correct 721 ms 4408 KB Output is correct
55 Execution timed out 1091 ms 6628 KB Time limit exceeded
56 Halted 0 ms 0 KB -