#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;
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.count() << '\n';
for(int i=0; i<(int)maxn*maxn; i++){
if(potencijal[i]){
cout << i << ' ';
}
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
3 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 |
2 ms |
492 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 |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
3 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 |
2 ms |
492 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 |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
9 ms |
748 KB |
Output is correct |
22 |
Correct |
11 ms |
748 KB |
Output is correct |
23 |
Correct |
5 ms |
620 KB |
Output is correct |
24 |
Correct |
18 ms |
876 KB |
Output is correct |
25 |
Correct |
29 ms |
876 KB |
Output is correct |
26 |
Correct |
33 ms |
876 KB |
Output is correct |
27 |
Correct |
31 ms |
876 KB |
Output is correct |
28 |
Correct |
35 ms |
876 KB |
Output is correct |
29 |
Correct |
35 ms |
876 KB |
Output is correct |
30 |
Correct |
19 ms |
876 KB |
Output is correct |
31 |
Correct |
27 ms |
876 KB |
Output is correct |
32 |
Correct |
21 ms |
876 KB |
Output is correct |
33 |
Correct |
40 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
3 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 |
2 ms |
492 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 |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
9 ms |
748 KB |
Output is correct |
22 |
Correct |
11 ms |
748 KB |
Output is correct |
23 |
Correct |
5 ms |
620 KB |
Output is correct |
24 |
Correct |
18 ms |
876 KB |
Output is correct |
25 |
Correct |
29 ms |
876 KB |
Output is correct |
26 |
Correct |
33 ms |
876 KB |
Output is correct |
27 |
Correct |
31 ms |
876 KB |
Output is correct |
28 |
Correct |
35 ms |
876 KB |
Output is correct |
29 |
Correct |
35 ms |
876 KB |
Output is correct |
30 |
Correct |
19 ms |
876 KB |
Output is correct |
31 |
Correct |
27 ms |
876 KB |
Output is correct |
32 |
Correct |
21 ms |
876 KB |
Output is correct |
33 |
Correct |
40 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 |
135 ms |
1732 KB |
Output is correct |
38 |
Correct |
135 ms |
1772 KB |
Output is correct |
39 |
Correct |
506 ms |
3436 KB |
Output is correct |
40 |
Correct |
299 ms |
2668 KB |
Output is correct |
41 |
Correct |
636 ms |
4076 KB |
Output is correct |
42 |
Correct |
259 ms |
2380 KB |
Output is correct |
43 |
Correct |
448 ms |
3180 KB |
Output is correct |
44 |
Correct |
466 ms |
3436 KB |
Output is correct |
45 |
Correct |
492 ms |
3436 KB |
Output is correct |
46 |
Correct |
281 ms |
2668 KB |
Output is correct |
47 |
Correct |
290 ms |
2540 KB |
Output is correct |
48 |
Correct |
507 ms |
3336 KB |
Output is correct |
49 |
Correct |
506 ms |
3348 KB |
Output is correct |
50 |
Correct |
274 ms |
2540 KB |
Output is correct |
51 |
Correct |
255 ms |
2540 KB |
Output is correct |
52 |
Correct |
628 ms |
3948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
3 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 |
2 ms |
492 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 |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
9 ms |
748 KB |
Output is correct |
22 |
Correct |
11 ms |
748 KB |
Output is correct |
23 |
Correct |
5 ms |
620 KB |
Output is correct |
24 |
Correct |
18 ms |
876 KB |
Output is correct |
25 |
Correct |
29 ms |
876 KB |
Output is correct |
26 |
Correct |
33 ms |
876 KB |
Output is correct |
27 |
Correct |
31 ms |
876 KB |
Output is correct |
28 |
Correct |
35 ms |
876 KB |
Output is correct |
29 |
Correct |
35 ms |
876 KB |
Output is correct |
30 |
Correct |
19 ms |
876 KB |
Output is correct |
31 |
Correct |
27 ms |
876 KB |
Output is correct |
32 |
Correct |
21 ms |
876 KB |
Output is correct |
33 |
Correct |
40 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 |
135 ms |
1732 KB |
Output is correct |
38 |
Correct |
135 ms |
1772 KB |
Output is correct |
39 |
Correct |
506 ms |
3436 KB |
Output is correct |
40 |
Correct |
299 ms |
2668 KB |
Output is correct |
41 |
Correct |
636 ms |
4076 KB |
Output is correct |
42 |
Correct |
259 ms |
2380 KB |
Output is correct |
43 |
Correct |
448 ms |
3180 KB |
Output is correct |
44 |
Correct |
466 ms |
3436 KB |
Output is correct |
45 |
Correct |
492 ms |
3436 KB |
Output is correct |
46 |
Correct |
281 ms |
2668 KB |
Output is correct |
47 |
Correct |
290 ms |
2540 KB |
Output is correct |
48 |
Correct |
507 ms |
3336 KB |
Output is correct |
49 |
Correct |
506 ms |
3348 KB |
Output is correct |
50 |
Correct |
274 ms |
2540 KB |
Output is correct |
51 |
Correct |
255 ms |
2540 KB |
Output is correct |
52 |
Correct |
628 ms |
3948 KB |
Output is correct |
53 |
Correct |
457 ms |
3564 KB |
Output is correct |
54 |
Correct |
655 ms |
4460 KB |
Output is correct |
55 |
Execution timed out |
1092 ms |
6508 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
3 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 |
2 ms |
492 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 |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
9 ms |
748 KB |
Output is correct |
22 |
Correct |
11 ms |
748 KB |
Output is correct |
23 |
Correct |
5 ms |
620 KB |
Output is correct |
24 |
Correct |
18 ms |
876 KB |
Output is correct |
25 |
Correct |
29 ms |
876 KB |
Output is correct |
26 |
Correct |
33 ms |
876 KB |
Output is correct |
27 |
Correct |
31 ms |
876 KB |
Output is correct |
28 |
Correct |
35 ms |
876 KB |
Output is correct |
29 |
Correct |
35 ms |
876 KB |
Output is correct |
30 |
Correct |
19 ms |
876 KB |
Output is correct |
31 |
Correct |
27 ms |
876 KB |
Output is correct |
32 |
Correct |
21 ms |
876 KB |
Output is correct |
33 |
Correct |
40 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 |
135 ms |
1732 KB |
Output is correct |
38 |
Correct |
135 ms |
1772 KB |
Output is correct |
39 |
Correct |
506 ms |
3436 KB |
Output is correct |
40 |
Correct |
299 ms |
2668 KB |
Output is correct |
41 |
Correct |
636 ms |
4076 KB |
Output is correct |
42 |
Correct |
259 ms |
2380 KB |
Output is correct |
43 |
Correct |
448 ms |
3180 KB |
Output is correct |
44 |
Correct |
466 ms |
3436 KB |
Output is correct |
45 |
Correct |
492 ms |
3436 KB |
Output is correct |
46 |
Correct |
281 ms |
2668 KB |
Output is correct |
47 |
Correct |
290 ms |
2540 KB |
Output is correct |
48 |
Correct |
507 ms |
3336 KB |
Output is correct |
49 |
Correct |
506 ms |
3348 KB |
Output is correct |
50 |
Correct |
274 ms |
2540 KB |
Output is correct |
51 |
Correct |
255 ms |
2540 KB |
Output is correct |
52 |
Correct |
628 ms |
3948 KB |
Output is correct |
53 |
Correct |
457 ms |
3564 KB |
Output is correct |
54 |
Correct |
655 ms |
4460 KB |
Output is correct |
55 |
Execution timed out |
1092 ms |
6508 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |