Submission #386278

# Submission time Handle Problem Language Result Execution time Memory
386278 2021-04-06T09:11:28 Z vanic Bootfall (IZhO17_bootfall) C++14
44 / 100
1000 ms 6508 KB
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <cstring>
#include <array>
#include <bitset>
#include <cassert>

using namespace std;

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

bitset < maxn*maxn > potencijal;

int sum;
bitset < maxn*maxn > dp[maxn];
int n;
int br;
int tren;
int p;

void dodaj(int x){
	for(int i=sum; i>=x; --i){
		dp[br][i]=dp[br-1][i-x]|dp[br-1][i];
	}
	for(int i=0; i<x; ++i){
		dp[br][i]=dp[br-1][i];
	}
	br++;
}


void probaj(){
	if(p==2){
		if((tren&1) || !dp[br-1][tren/2]){
			p=0;
		}
		else{
			p=1;
		}
//		cout << "hehe " << p <<  endl;
	}
	else if(p){
		for(int i=1; i<sum; ++i){
			if(!((i+tren)&1) && dp[br-1][(i+tren)/2]){
				potencijal[i]=1;
			}
		}
		p=0;
	}
	else{
		for(int i=0; i<sum; i++){
			if(potencijal[i] && (((i+tren)&1) || !dp[br-1][(i+tren)/2])){
				potencijal[i]=0;
			}
		}
	}
}

struct tournament{
	vector < int > t[pot*2];
	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 rokaj(int x){
		for(int i=0; i<(int)t[x].size(); i++){
			tren+=t[x][i];
			dodaj(t[x][i]);
		}
		if(x>=pot){
			if(p==2 || br==n){
//				cout << br << endl;
//				cout << "uso" << endl;
				probaj();
			}
			br-=t[x].size();
			for(int i=0; i<(int)t[x].size(); i++){
				tren-=t[x][i];
			}
			return;
		}
		rokaj(x*2);
		rokaj(x*2+1);
		br-=t[x].size();
		for(int i=0; i<(int)t[x].size(); i++){
			tren-=t[x][i];
		}
	}
};

int a[maxn];
tournament T;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	int par=0, nepar=0;
	for(int i=0; i<n; i++){
		cin >> a[i];
		sum+=a[i];
		if(a[i]&1){
			nepar++;
		}
		else{
			par++;
		}
		T.update(0, pot-1,  1, 0, i, a[i]);
		T.update(0, pot-1, 1, i+2, pot, a[i]);
	}
	if((par && nepar) || (n&1)){
		cout << 0 << '\n';
		return 0;
	}
	dp[0][0]=1;
	br=1;
	p=2;
	T.rokaj(1);
	cout << potencijal.count() << '\n';
	for(int i=0; i<(int)maxn*maxn; i++){
		if(potencijal[i]){
			cout << i << ' ';
		}
	}
	cout << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 8 ms 620 KB Output is correct
22 Correct 10 ms 748 KB Output is correct
23 Correct 5 ms 620 KB Output is correct
24 Correct 17 ms 876 KB Output is correct
25 Correct 32 ms 1004 KB Output is correct
26 Correct 34 ms 876 KB Output is correct
27 Correct 32 ms 876 KB Output is correct
28 Correct 34 ms 876 KB Output is correct
29 Correct 34 ms 876 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 27 ms 876 KB Output is correct
32 Correct 18 ms 876 KB Output is correct
33 Correct 35 ms 876 KB Output is correct
34 Correct 34 ms 876 KB Output is correct
35 Correct 34 ms 876 KB Output is correct
36 Correct 17 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 8 ms 620 KB Output is correct
22 Correct 10 ms 748 KB Output is correct
23 Correct 5 ms 620 KB Output is correct
24 Correct 17 ms 876 KB Output is correct
25 Correct 32 ms 1004 KB Output is correct
26 Correct 34 ms 876 KB Output is correct
27 Correct 32 ms 876 KB Output is correct
28 Correct 34 ms 876 KB Output is correct
29 Correct 34 ms 876 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 27 ms 876 KB Output is correct
32 Correct 18 ms 876 KB Output is correct
33 Correct 35 ms 876 KB Output is correct
34 Correct 34 ms 876 KB Output is correct
35 Correct 34 ms 876 KB Output is correct
36 Correct 17 ms 876 KB Output is correct
37 Correct 136 ms 1732 KB Output is correct
38 Correct 135 ms 1772 KB Output is correct
39 Correct 511 ms 3436 KB Output is correct
40 Correct 300 ms 2668 KB Output is correct
41 Correct 655 ms 4076 KB Output is correct
42 Correct 256 ms 2412 KB Output is correct
43 Correct 452 ms 3328 KB Output is correct
44 Correct 473 ms 3308 KB Output is correct
45 Correct 476 ms 3320 KB Output is correct
46 Correct 283 ms 2668 KB Output is correct
47 Correct 274 ms 2540 KB Output is correct
48 Correct 517 ms 3348 KB Output is correct
49 Correct 509 ms 3308 KB Output is correct
50 Correct 282 ms 2540 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 632 ms 4076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 8 ms 620 KB Output is correct
22 Correct 10 ms 748 KB Output is correct
23 Correct 5 ms 620 KB Output is correct
24 Correct 17 ms 876 KB Output is correct
25 Correct 32 ms 1004 KB Output is correct
26 Correct 34 ms 876 KB Output is correct
27 Correct 32 ms 876 KB Output is correct
28 Correct 34 ms 876 KB Output is correct
29 Correct 34 ms 876 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 27 ms 876 KB Output is correct
32 Correct 18 ms 876 KB Output is correct
33 Correct 35 ms 876 KB Output is correct
34 Correct 34 ms 876 KB Output is correct
35 Correct 34 ms 876 KB Output is correct
36 Correct 17 ms 876 KB Output is correct
37 Correct 136 ms 1732 KB Output is correct
38 Correct 135 ms 1772 KB Output is correct
39 Correct 511 ms 3436 KB Output is correct
40 Correct 300 ms 2668 KB Output is correct
41 Correct 655 ms 4076 KB Output is correct
42 Correct 256 ms 2412 KB Output is correct
43 Correct 452 ms 3328 KB Output is correct
44 Correct 473 ms 3308 KB Output is correct
45 Correct 476 ms 3320 KB Output is correct
46 Correct 283 ms 2668 KB Output is correct
47 Correct 274 ms 2540 KB Output is correct
48 Correct 517 ms 3348 KB Output is correct
49 Correct 509 ms 3308 KB Output is correct
50 Correct 282 ms 2540 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 632 ms 4076 KB Output is correct
53 Correct 465 ms 3564 KB Output is correct
54 Correct 654 ms 4332 KB Output is correct
55 Execution timed out 1093 ms 6508 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 8 ms 620 KB Output is correct
22 Correct 10 ms 748 KB Output is correct
23 Correct 5 ms 620 KB Output is correct
24 Correct 17 ms 876 KB Output is correct
25 Correct 32 ms 1004 KB Output is correct
26 Correct 34 ms 876 KB Output is correct
27 Correct 32 ms 876 KB Output is correct
28 Correct 34 ms 876 KB Output is correct
29 Correct 34 ms 876 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 27 ms 876 KB Output is correct
32 Correct 18 ms 876 KB Output is correct
33 Correct 35 ms 876 KB Output is correct
34 Correct 34 ms 876 KB Output is correct
35 Correct 34 ms 876 KB Output is correct
36 Correct 17 ms 876 KB Output is correct
37 Correct 136 ms 1732 KB Output is correct
38 Correct 135 ms 1772 KB Output is correct
39 Correct 511 ms 3436 KB Output is correct
40 Correct 300 ms 2668 KB Output is correct
41 Correct 655 ms 4076 KB Output is correct
42 Correct 256 ms 2412 KB Output is correct
43 Correct 452 ms 3328 KB Output is correct
44 Correct 473 ms 3308 KB Output is correct
45 Correct 476 ms 3320 KB Output is correct
46 Correct 283 ms 2668 KB Output is correct
47 Correct 274 ms 2540 KB Output is correct
48 Correct 517 ms 3348 KB Output is correct
49 Correct 509 ms 3308 KB Output is correct
50 Correct 282 ms 2540 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 632 ms 4076 KB Output is correct
53 Correct 465 ms 3564 KB Output is correct
54 Correct 654 ms 4332 KB Output is correct
55 Execution timed out 1093 ms 6508 KB Time limit exceeded
56 Halted 0 ms 0 KB -