Submission #514767

# Submission time Handle Problem Language Result Execution time Memory
514767 2022-01-18T13:07:36 Z ymm Bootfall (IZhO17_bootfall) C++17
100 / 100
217 ms 17832 KB
///
///   What would happen if we used assembly language for CP?
///   Sorry, that was a strange thing to ask.
///

#include <bits/stdc++.h>
#define Loop(x,l,r) for(ll x = ll(l); x < ll(r); ++x)
#define LoopR(x,l,r) for(ll x = ll(r)-1; x >= ll(l); --x)
#define Kill(x) exit((cout << (x) << '\n', 0))
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
using namespace std;

const int N = 505;
int a[N];
bitset<N*N> bs[N];
int n;
int sum=0;

vector<int> t[N<<2];
bitset<N*N> dc[11]; int dcc=0;
void add(int l, int r, int x, int i=0, int b=0, int e=N){
	if(r<=b||e<=l||l>=r) return;
	if(l<=b&&e<=r) {t[i].push_back(x); return;}
	add(l,r,x,2*i+1,b,(b+e)/2);
	add(l,r,x,2*i+2,(b+e)/2,e);
}
void push(int i){
	dc[dcc+1] = dc[dcc];
	++dcc;
	for(int x : t[i]) dc[dcc] = dc[dcc]|(dc[dcc]<<x);
}
void dfs(int i=0, int b=0, int e=N){
	push(i);
	if(e-b==1){bs[b]=dc[dcc];--dcc;return;}
	dfs(2*i+1,b,(b+e)/2);
	dfs(2*i+2,(b+e)/2,e);
	--dcc;
}

bool test(int x){
	Loop(i,0,n){
		if(sum-a[i]-x<0) return 0;
		if((sum-a[i]-x)&1) return 0;
		if(!bs[i][(sum-a[i]-x)/2]) return 0;
	}
	return 1;
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n;
	Loop(i,0,n){
		cin >> a[i];
		add(0,i,a[i]);
		add(i+1,n+1,a[i]);
		sum += a[i];
	}
	dc[0][0]=1;
	dfs();
	//Loop(i,0,n+1) {Loop(j,0,50) cout<<bs[i][j]; cout << '\n';}
	if((sum&1) || !bs[n][sum/2]) Kill("0\n");
	vector<int> ans;
	Loop(i,0,N*N) if(test(i)) ans.push_back(i);
	cout << ans.size() << '\n';
	for(int x : ans) cout << x << ' ';
	cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16360 KB Output is correct
2 Correct 11 ms 16460 KB Output is correct
3 Correct 10 ms 16460 KB Output is correct
4 Correct 10 ms 16460 KB Output is correct
5 Correct 12 ms 16460 KB Output is correct
6 Correct 9 ms 16460 KB Output is correct
7 Correct 9 ms 16460 KB Output is correct
8 Correct 10 ms 16380 KB Output is correct
9 Correct 10 ms 16404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16360 KB Output is correct
2 Correct 11 ms 16460 KB Output is correct
3 Correct 10 ms 16460 KB Output is correct
4 Correct 10 ms 16460 KB Output is correct
5 Correct 12 ms 16460 KB Output is correct
6 Correct 9 ms 16460 KB Output is correct
7 Correct 9 ms 16460 KB Output is correct
8 Correct 10 ms 16380 KB Output is correct
9 Correct 10 ms 16404 KB Output is correct
10 Correct 14 ms 16384 KB Output is correct
11 Correct 10 ms 16460 KB Output is correct
12 Correct 10 ms 16440 KB Output is correct
13 Correct 12 ms 16424 KB Output is correct
14 Correct 11 ms 16492 KB Output is correct
15 Correct 11 ms 16500 KB Output is correct
16 Correct 10 ms 16404 KB Output is correct
17 Correct 12 ms 16460 KB Output is correct
18 Correct 10 ms 16488 KB Output is correct
19 Correct 12 ms 16460 KB Output is correct
20 Correct 11 ms 16460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16360 KB Output is correct
2 Correct 11 ms 16460 KB Output is correct
3 Correct 10 ms 16460 KB Output is correct
4 Correct 10 ms 16460 KB Output is correct
5 Correct 12 ms 16460 KB Output is correct
6 Correct 9 ms 16460 KB Output is correct
7 Correct 9 ms 16460 KB Output is correct
8 Correct 10 ms 16380 KB Output is correct
9 Correct 10 ms 16404 KB Output is correct
10 Correct 14 ms 16384 KB Output is correct
11 Correct 10 ms 16460 KB Output is correct
12 Correct 10 ms 16440 KB Output is correct
13 Correct 12 ms 16424 KB Output is correct
14 Correct 11 ms 16492 KB Output is correct
15 Correct 11 ms 16500 KB Output is correct
16 Correct 10 ms 16404 KB Output is correct
17 Correct 12 ms 16460 KB Output is correct
18 Correct 10 ms 16488 KB Output is correct
19 Correct 12 ms 16460 KB Output is correct
20 Correct 11 ms 16460 KB Output is correct
21 Correct 16 ms 16452 KB Output is correct
22 Correct 16 ms 16496 KB Output is correct
23 Correct 12 ms 16460 KB Output is correct
24 Correct 17 ms 16508 KB Output is correct
25 Correct 18 ms 16540 KB Output is correct
26 Correct 18 ms 16508 KB Output is correct
27 Correct 19 ms 16412 KB Output is correct
28 Correct 23 ms 16424 KB Output is correct
29 Correct 21 ms 16460 KB Output is correct
30 Correct 19 ms 16408 KB Output is correct
31 Correct 26 ms 16468 KB Output is correct
32 Correct 20 ms 16468 KB Output is correct
33 Correct 25 ms 16524 KB Output is correct
34 Correct 19 ms 16496 KB Output is correct
35 Correct 19 ms 16460 KB Output is correct
36 Correct 17 ms 16424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16360 KB Output is correct
2 Correct 11 ms 16460 KB Output is correct
3 Correct 10 ms 16460 KB Output is correct
4 Correct 10 ms 16460 KB Output is correct
5 Correct 12 ms 16460 KB Output is correct
6 Correct 9 ms 16460 KB Output is correct
7 Correct 9 ms 16460 KB Output is correct
8 Correct 10 ms 16380 KB Output is correct
9 Correct 10 ms 16404 KB Output is correct
10 Correct 14 ms 16384 KB Output is correct
11 Correct 10 ms 16460 KB Output is correct
12 Correct 10 ms 16440 KB Output is correct
13 Correct 12 ms 16424 KB Output is correct
14 Correct 11 ms 16492 KB Output is correct
15 Correct 11 ms 16500 KB Output is correct
16 Correct 10 ms 16404 KB Output is correct
17 Correct 12 ms 16460 KB Output is correct
18 Correct 10 ms 16488 KB Output is correct
19 Correct 12 ms 16460 KB Output is correct
20 Correct 11 ms 16460 KB Output is correct
21 Correct 16 ms 16452 KB Output is correct
22 Correct 16 ms 16496 KB Output is correct
23 Correct 12 ms 16460 KB Output is correct
24 Correct 17 ms 16508 KB Output is correct
25 Correct 18 ms 16540 KB Output is correct
26 Correct 18 ms 16508 KB Output is correct
27 Correct 19 ms 16412 KB Output is correct
28 Correct 23 ms 16424 KB Output is correct
29 Correct 21 ms 16460 KB Output is correct
30 Correct 19 ms 16408 KB Output is correct
31 Correct 26 ms 16468 KB Output is correct
32 Correct 20 ms 16468 KB Output is correct
33 Correct 25 ms 16524 KB Output is correct
34 Correct 19 ms 16496 KB Output is correct
35 Correct 19 ms 16460 KB Output is correct
36 Correct 17 ms 16424 KB Output is correct
37 Correct 32 ms 16688 KB Output is correct
38 Correct 35 ms 16632 KB Output is correct
39 Correct 35 ms 16460 KB Output is correct
40 Correct 56 ms 16676 KB Output is correct
41 Correct 32 ms 16436 KB Output is correct
42 Correct 47 ms 16688 KB Output is correct
43 Correct 55 ms 16756 KB Output is correct
44 Correct 71 ms 16880 KB Output is correct
45 Correct 74 ms 16880 KB Output is correct
46 Correct 38 ms 16372 KB Output is correct
47 Correct 54 ms 16692 KB Output is correct
48 Correct 74 ms 16740 KB Output is correct
49 Correct 66 ms 16512 KB Output is correct
50 Correct 55 ms 16688 KB Output is correct
51 Correct 42 ms 16480 KB Output is correct
52 Correct 55 ms 16884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16360 KB Output is correct
2 Correct 11 ms 16460 KB Output is correct
3 Correct 10 ms 16460 KB Output is correct
4 Correct 10 ms 16460 KB Output is correct
5 Correct 12 ms 16460 KB Output is correct
6 Correct 9 ms 16460 KB Output is correct
7 Correct 9 ms 16460 KB Output is correct
8 Correct 10 ms 16380 KB Output is correct
9 Correct 10 ms 16404 KB Output is correct
10 Correct 14 ms 16384 KB Output is correct
11 Correct 10 ms 16460 KB Output is correct
12 Correct 10 ms 16440 KB Output is correct
13 Correct 12 ms 16424 KB Output is correct
14 Correct 11 ms 16492 KB Output is correct
15 Correct 11 ms 16500 KB Output is correct
16 Correct 10 ms 16404 KB Output is correct
17 Correct 12 ms 16460 KB Output is correct
18 Correct 10 ms 16488 KB Output is correct
19 Correct 12 ms 16460 KB Output is correct
20 Correct 11 ms 16460 KB Output is correct
21 Correct 16 ms 16452 KB Output is correct
22 Correct 16 ms 16496 KB Output is correct
23 Correct 12 ms 16460 KB Output is correct
24 Correct 17 ms 16508 KB Output is correct
25 Correct 18 ms 16540 KB Output is correct
26 Correct 18 ms 16508 KB Output is correct
27 Correct 19 ms 16412 KB Output is correct
28 Correct 23 ms 16424 KB Output is correct
29 Correct 21 ms 16460 KB Output is correct
30 Correct 19 ms 16408 KB Output is correct
31 Correct 26 ms 16468 KB Output is correct
32 Correct 20 ms 16468 KB Output is correct
33 Correct 25 ms 16524 KB Output is correct
34 Correct 19 ms 16496 KB Output is correct
35 Correct 19 ms 16460 KB Output is correct
36 Correct 17 ms 16424 KB Output is correct
37 Correct 32 ms 16688 KB Output is correct
38 Correct 35 ms 16632 KB Output is correct
39 Correct 35 ms 16460 KB Output is correct
40 Correct 56 ms 16676 KB Output is correct
41 Correct 32 ms 16436 KB Output is correct
42 Correct 47 ms 16688 KB Output is correct
43 Correct 55 ms 16756 KB Output is correct
44 Correct 71 ms 16880 KB Output is correct
45 Correct 74 ms 16880 KB Output is correct
46 Correct 38 ms 16372 KB Output is correct
47 Correct 54 ms 16692 KB Output is correct
48 Correct 74 ms 16740 KB Output is correct
49 Correct 66 ms 16512 KB Output is correct
50 Correct 55 ms 16688 KB Output is correct
51 Correct 42 ms 16480 KB Output is correct
52 Correct 55 ms 16884 KB Output is correct
53 Correct 53 ms 16832 KB Output is correct
54 Correct 74 ms 16876 KB Output is correct
55 Correct 113 ms 17128 KB Output is correct
56 Correct 61 ms 16808 KB Output is correct
57 Correct 91 ms 17104 KB Output is correct
58 Correct 83 ms 16944 KB Output is correct
59 Correct 90 ms 17000 KB Output is correct
60 Correct 43 ms 16420 KB Output is correct
61 Correct 78 ms 16948 KB Output is correct
62 Correct 104 ms 17088 KB Output is correct
63 Correct 88 ms 17012 KB Output is correct
64 Correct 110 ms 17060 KB Output is correct
65 Correct 54 ms 16452 KB Output is correct
66 Correct 48 ms 16604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16360 KB Output is correct
2 Correct 11 ms 16460 KB Output is correct
3 Correct 10 ms 16460 KB Output is correct
4 Correct 10 ms 16460 KB Output is correct
5 Correct 12 ms 16460 KB Output is correct
6 Correct 9 ms 16460 KB Output is correct
7 Correct 9 ms 16460 KB Output is correct
8 Correct 10 ms 16380 KB Output is correct
9 Correct 10 ms 16404 KB Output is correct
10 Correct 14 ms 16384 KB Output is correct
11 Correct 10 ms 16460 KB Output is correct
12 Correct 10 ms 16440 KB Output is correct
13 Correct 12 ms 16424 KB Output is correct
14 Correct 11 ms 16492 KB Output is correct
15 Correct 11 ms 16500 KB Output is correct
16 Correct 10 ms 16404 KB Output is correct
17 Correct 12 ms 16460 KB Output is correct
18 Correct 10 ms 16488 KB Output is correct
19 Correct 12 ms 16460 KB Output is correct
20 Correct 11 ms 16460 KB Output is correct
21 Correct 16 ms 16452 KB Output is correct
22 Correct 16 ms 16496 KB Output is correct
23 Correct 12 ms 16460 KB Output is correct
24 Correct 17 ms 16508 KB Output is correct
25 Correct 18 ms 16540 KB Output is correct
26 Correct 18 ms 16508 KB Output is correct
27 Correct 19 ms 16412 KB Output is correct
28 Correct 23 ms 16424 KB Output is correct
29 Correct 21 ms 16460 KB Output is correct
30 Correct 19 ms 16408 KB Output is correct
31 Correct 26 ms 16468 KB Output is correct
32 Correct 20 ms 16468 KB Output is correct
33 Correct 25 ms 16524 KB Output is correct
34 Correct 19 ms 16496 KB Output is correct
35 Correct 19 ms 16460 KB Output is correct
36 Correct 17 ms 16424 KB Output is correct
37 Correct 32 ms 16688 KB Output is correct
38 Correct 35 ms 16632 KB Output is correct
39 Correct 35 ms 16460 KB Output is correct
40 Correct 56 ms 16676 KB Output is correct
41 Correct 32 ms 16436 KB Output is correct
42 Correct 47 ms 16688 KB Output is correct
43 Correct 55 ms 16756 KB Output is correct
44 Correct 71 ms 16880 KB Output is correct
45 Correct 74 ms 16880 KB Output is correct
46 Correct 38 ms 16372 KB Output is correct
47 Correct 54 ms 16692 KB Output is correct
48 Correct 74 ms 16740 KB Output is correct
49 Correct 66 ms 16512 KB Output is correct
50 Correct 55 ms 16688 KB Output is correct
51 Correct 42 ms 16480 KB Output is correct
52 Correct 55 ms 16884 KB Output is correct
53 Correct 53 ms 16832 KB Output is correct
54 Correct 74 ms 16876 KB Output is correct
55 Correct 113 ms 17128 KB Output is correct
56 Correct 61 ms 16808 KB Output is correct
57 Correct 91 ms 17104 KB Output is correct
58 Correct 83 ms 16944 KB Output is correct
59 Correct 90 ms 17000 KB Output is correct
60 Correct 43 ms 16420 KB Output is correct
61 Correct 78 ms 16948 KB Output is correct
62 Correct 104 ms 17088 KB Output is correct
63 Correct 88 ms 17012 KB Output is correct
64 Correct 110 ms 17060 KB Output is correct
65 Correct 54 ms 16452 KB Output is correct
66 Correct 48 ms 16604 KB Output is correct
67 Correct 90 ms 16920 KB Output is correct
68 Correct 77 ms 16532 KB Output is correct
69 Correct 175 ms 17640 KB Output is correct
70 Correct 142 ms 17260 KB Output is correct
71 Correct 165 ms 17200 KB Output is correct
72 Correct 73 ms 16452 KB Output is correct
73 Correct 77 ms 16452 KB Output is correct
74 Correct 175 ms 17684 KB Output is correct
75 Correct 172 ms 17520 KB Output is correct
76 Correct 217 ms 17700 KB Output is correct
77 Correct 214 ms 17832 KB Output is correct