Submission #386271

# Submission time Handle Problem Language Result Execution time Memory
386271 2021-04-06T08:57:08 Z vanic Bootfall (IZhO17_bootfall) C++14
44 / 100
1000 ms 7460 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);

vector < int > 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(){
	vector < int > novi;
	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<maxn*maxn; ++i){
			if(!((i+tren)&1) && dp[br-1][(i+tren)/2]){
				potencijal.push_back(i);
			}
		}
		p=0;
	}
	else{
		for(int i=0; i<(int)potencijal.size(); i++){
			if(!((potencijal[i]+tren)&1) && dp[br-1][(potencijal[i]+tren)/2]){
				novi.push_back(potencijal[i]);
			}
		}
		potencijal=novi;
	}
}

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;
	for(int i=0; i<n; i++){
		cin >> a[i];
		sum+=a[i];
		T.update(0, pot-1,  1, 0, i, a[i]);
		T.update(0, pot-1, 1, i+2, pot, a[i]);
	}
	dp[0][0]=1;
	br=1;
	p=2;
	T.rokaj(1);
	cout << potencijal.size() << '\n';
	for(int i=0; i<(int)potencijal.size(); i++){
		cout << potencijal[i] << ' ';
	}
	cout << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 3 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 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 3 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 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 3 ms 492 KB Output is correct
21 Correct 9 ms 620 KB Output is correct
22 Correct 11 ms 748 KB Output is correct
23 Correct 6 ms 620 KB Output is correct
24 Correct 17 ms 876 KB Output is correct
25 Correct 30 ms 876 KB Output is correct
26 Correct 35 ms 1004 KB Output is correct
27 Correct 31 ms 896 KB Output is correct
28 Correct 33 ms 876 KB Output is correct
29 Correct 35 ms 876 KB Output is correct
30 Correct 21 ms 876 KB Output is correct
31 Correct 32 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 33 ms 876 KB Output is correct
35 Correct 34 ms 876 KB Output is correct
36 Correct 19 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 3 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 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 3 ms 492 KB Output is correct
21 Correct 9 ms 620 KB Output is correct
22 Correct 11 ms 748 KB Output is correct
23 Correct 6 ms 620 KB Output is correct
24 Correct 17 ms 876 KB Output is correct
25 Correct 30 ms 876 KB Output is correct
26 Correct 35 ms 1004 KB Output is correct
27 Correct 31 ms 896 KB Output is correct
28 Correct 33 ms 876 KB Output is correct
29 Correct 35 ms 876 KB Output is correct
30 Correct 21 ms 876 KB Output is correct
31 Correct 32 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 33 ms 876 KB Output is correct
35 Correct 34 ms 876 KB Output is correct
36 Correct 19 ms 876 KB Output is correct
37 Correct 134 ms 1900 KB Output is correct
38 Correct 136 ms 1920 KB Output is correct
39 Correct 485 ms 3436 KB Output is correct
40 Correct 301 ms 2796 KB Output is correct
41 Correct 623 ms 3948 KB Output is correct
42 Correct 254 ms 2668 KB Output is correct
43 Correct 453 ms 3588 KB Output is correct
44 Correct 467 ms 3712 KB Output is correct
45 Correct 490 ms 3724 KB Output is correct
46 Correct 272 ms 2688 KB Output is correct
47 Correct 274 ms 2668 KB Output is correct
48 Correct 511 ms 3728 KB Output is correct
49 Correct 494 ms 3564 KB Output is correct
50 Correct 277 ms 2668 KB Output is correct
51 Correct 259 ms 2540 KB Output is correct
52 Correct 631 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 3 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 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 3 ms 492 KB Output is correct
21 Correct 9 ms 620 KB Output is correct
22 Correct 11 ms 748 KB Output is correct
23 Correct 6 ms 620 KB Output is correct
24 Correct 17 ms 876 KB Output is correct
25 Correct 30 ms 876 KB Output is correct
26 Correct 35 ms 1004 KB Output is correct
27 Correct 31 ms 896 KB Output is correct
28 Correct 33 ms 876 KB Output is correct
29 Correct 35 ms 876 KB Output is correct
30 Correct 21 ms 876 KB Output is correct
31 Correct 32 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 33 ms 876 KB Output is correct
35 Correct 34 ms 876 KB Output is correct
36 Correct 19 ms 876 KB Output is correct
37 Correct 134 ms 1900 KB Output is correct
38 Correct 136 ms 1920 KB Output is correct
39 Correct 485 ms 3436 KB Output is correct
40 Correct 301 ms 2796 KB Output is correct
41 Correct 623 ms 3948 KB Output is correct
42 Correct 254 ms 2668 KB Output is correct
43 Correct 453 ms 3588 KB Output is correct
44 Correct 467 ms 3712 KB Output is correct
45 Correct 490 ms 3724 KB Output is correct
46 Correct 272 ms 2688 KB Output is correct
47 Correct 274 ms 2668 KB Output is correct
48 Correct 511 ms 3728 KB Output is correct
49 Correct 494 ms 3564 KB Output is correct
50 Correct 277 ms 2668 KB Output is correct
51 Correct 259 ms 2540 KB Output is correct
52 Correct 631 ms 4344 KB Output is correct
53 Correct 462 ms 3772 KB Output is correct
54 Correct 653 ms 4676 KB Output is correct
55 Execution timed out 1094 ms 7460 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 3 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 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 3 ms 492 KB Output is correct
21 Correct 9 ms 620 KB Output is correct
22 Correct 11 ms 748 KB Output is correct
23 Correct 6 ms 620 KB Output is correct
24 Correct 17 ms 876 KB Output is correct
25 Correct 30 ms 876 KB Output is correct
26 Correct 35 ms 1004 KB Output is correct
27 Correct 31 ms 896 KB Output is correct
28 Correct 33 ms 876 KB Output is correct
29 Correct 35 ms 876 KB Output is correct
30 Correct 21 ms 876 KB Output is correct
31 Correct 32 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 33 ms 876 KB Output is correct
35 Correct 34 ms 876 KB Output is correct
36 Correct 19 ms 876 KB Output is correct
37 Correct 134 ms 1900 KB Output is correct
38 Correct 136 ms 1920 KB Output is correct
39 Correct 485 ms 3436 KB Output is correct
40 Correct 301 ms 2796 KB Output is correct
41 Correct 623 ms 3948 KB Output is correct
42 Correct 254 ms 2668 KB Output is correct
43 Correct 453 ms 3588 KB Output is correct
44 Correct 467 ms 3712 KB Output is correct
45 Correct 490 ms 3724 KB Output is correct
46 Correct 272 ms 2688 KB Output is correct
47 Correct 274 ms 2668 KB Output is correct
48 Correct 511 ms 3728 KB Output is correct
49 Correct 494 ms 3564 KB Output is correct
50 Correct 277 ms 2668 KB Output is correct
51 Correct 259 ms 2540 KB Output is correct
52 Correct 631 ms 4344 KB Output is correct
53 Correct 462 ms 3772 KB Output is correct
54 Correct 653 ms 4676 KB Output is correct
55 Execution timed out 1094 ms 7460 KB Time limit exceeded
56 Halted 0 ms 0 KB -