#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<sum; ++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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
2 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 |
1 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 |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
492 KB |
Output is correct |
11 |
Correct |
1 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 |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
492 KB |
Output is correct |
11 |
Correct |
1 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 |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 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 |
9 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 |
16 ms |
876 KB |
Output is correct |
25 |
Correct |
29 ms |
876 KB |
Output is correct |
26 |
Correct |
33 ms |
1004 KB |
Output is correct |
27 |
Correct |
30 ms |
876 KB |
Output is correct |
28 |
Correct |
33 ms |
1004 KB |
Output is correct |
29 |
Correct |
33 ms |
876 KB |
Output is correct |
30 |
Correct |
20 ms |
876 KB |
Output is correct |
31 |
Correct |
28 ms |
1004 KB |
Output is correct |
32 |
Correct |
18 ms |
876 KB |
Output is correct |
33 |
Correct |
33 ms |
876 KB |
Output is correct |
34 |
Correct |
33 ms |
876 KB |
Output is correct |
35 |
Correct |
32 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 |
1 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 |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
492 KB |
Output is correct |
11 |
Correct |
1 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 |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 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 |
9 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 |
16 ms |
876 KB |
Output is correct |
25 |
Correct |
29 ms |
876 KB |
Output is correct |
26 |
Correct |
33 ms |
1004 KB |
Output is correct |
27 |
Correct |
30 ms |
876 KB |
Output is correct |
28 |
Correct |
33 ms |
1004 KB |
Output is correct |
29 |
Correct |
33 ms |
876 KB |
Output is correct |
30 |
Correct |
20 ms |
876 KB |
Output is correct |
31 |
Correct |
28 ms |
1004 KB |
Output is correct |
32 |
Correct |
18 ms |
876 KB |
Output is correct |
33 |
Correct |
33 ms |
876 KB |
Output is correct |
34 |
Correct |
33 ms |
876 KB |
Output is correct |
35 |
Correct |
32 ms |
876 KB |
Output is correct |
36 |
Correct |
17 ms |
876 KB |
Output is correct |
37 |
Correct |
132 ms |
1900 KB |
Output is correct |
38 |
Correct |
137 ms |
1900 KB |
Output is correct |
39 |
Correct |
484 ms |
3308 KB |
Output is correct |
40 |
Correct |
297 ms |
2796 KB |
Output is correct |
41 |
Correct |
621 ms |
3948 KB |
Output is correct |
42 |
Correct |
254 ms |
2540 KB |
Output is correct |
43 |
Correct |
450 ms |
3464 KB |
Output is correct |
44 |
Correct |
464 ms |
3584 KB |
Output is correct |
45 |
Correct |
477 ms |
3712 KB |
Output is correct |
46 |
Correct |
270 ms |
2668 KB |
Output is correct |
47 |
Correct |
273 ms |
2668 KB |
Output is correct |
48 |
Correct |
505 ms |
3728 KB |
Output is correct |
49 |
Correct |
489 ms |
3460 KB |
Output is correct |
50 |
Correct |
281 ms |
2668 KB |
Output is correct |
51 |
Correct |
265 ms |
2412 KB |
Output is correct |
52 |
Correct |
628 ms |
4344 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 |
1 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 |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
492 KB |
Output is correct |
11 |
Correct |
1 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 |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 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 |
9 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 |
16 ms |
876 KB |
Output is correct |
25 |
Correct |
29 ms |
876 KB |
Output is correct |
26 |
Correct |
33 ms |
1004 KB |
Output is correct |
27 |
Correct |
30 ms |
876 KB |
Output is correct |
28 |
Correct |
33 ms |
1004 KB |
Output is correct |
29 |
Correct |
33 ms |
876 KB |
Output is correct |
30 |
Correct |
20 ms |
876 KB |
Output is correct |
31 |
Correct |
28 ms |
1004 KB |
Output is correct |
32 |
Correct |
18 ms |
876 KB |
Output is correct |
33 |
Correct |
33 ms |
876 KB |
Output is correct |
34 |
Correct |
33 ms |
876 KB |
Output is correct |
35 |
Correct |
32 ms |
876 KB |
Output is correct |
36 |
Correct |
17 ms |
876 KB |
Output is correct |
37 |
Correct |
132 ms |
1900 KB |
Output is correct |
38 |
Correct |
137 ms |
1900 KB |
Output is correct |
39 |
Correct |
484 ms |
3308 KB |
Output is correct |
40 |
Correct |
297 ms |
2796 KB |
Output is correct |
41 |
Correct |
621 ms |
3948 KB |
Output is correct |
42 |
Correct |
254 ms |
2540 KB |
Output is correct |
43 |
Correct |
450 ms |
3464 KB |
Output is correct |
44 |
Correct |
464 ms |
3584 KB |
Output is correct |
45 |
Correct |
477 ms |
3712 KB |
Output is correct |
46 |
Correct |
270 ms |
2668 KB |
Output is correct |
47 |
Correct |
273 ms |
2668 KB |
Output is correct |
48 |
Correct |
505 ms |
3728 KB |
Output is correct |
49 |
Correct |
489 ms |
3460 KB |
Output is correct |
50 |
Correct |
281 ms |
2668 KB |
Output is correct |
51 |
Correct |
265 ms |
2412 KB |
Output is correct |
52 |
Correct |
628 ms |
4344 KB |
Output is correct |
53 |
Correct |
462 ms |
3856 KB |
Output is correct |
54 |
Correct |
656 ms |
4736 KB |
Output is correct |
55 |
Execution timed out |
1088 ms |
7628 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 |
1 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 |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
492 KB |
Output is correct |
11 |
Correct |
1 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 |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 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 |
9 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 |
16 ms |
876 KB |
Output is correct |
25 |
Correct |
29 ms |
876 KB |
Output is correct |
26 |
Correct |
33 ms |
1004 KB |
Output is correct |
27 |
Correct |
30 ms |
876 KB |
Output is correct |
28 |
Correct |
33 ms |
1004 KB |
Output is correct |
29 |
Correct |
33 ms |
876 KB |
Output is correct |
30 |
Correct |
20 ms |
876 KB |
Output is correct |
31 |
Correct |
28 ms |
1004 KB |
Output is correct |
32 |
Correct |
18 ms |
876 KB |
Output is correct |
33 |
Correct |
33 ms |
876 KB |
Output is correct |
34 |
Correct |
33 ms |
876 KB |
Output is correct |
35 |
Correct |
32 ms |
876 KB |
Output is correct |
36 |
Correct |
17 ms |
876 KB |
Output is correct |
37 |
Correct |
132 ms |
1900 KB |
Output is correct |
38 |
Correct |
137 ms |
1900 KB |
Output is correct |
39 |
Correct |
484 ms |
3308 KB |
Output is correct |
40 |
Correct |
297 ms |
2796 KB |
Output is correct |
41 |
Correct |
621 ms |
3948 KB |
Output is correct |
42 |
Correct |
254 ms |
2540 KB |
Output is correct |
43 |
Correct |
450 ms |
3464 KB |
Output is correct |
44 |
Correct |
464 ms |
3584 KB |
Output is correct |
45 |
Correct |
477 ms |
3712 KB |
Output is correct |
46 |
Correct |
270 ms |
2668 KB |
Output is correct |
47 |
Correct |
273 ms |
2668 KB |
Output is correct |
48 |
Correct |
505 ms |
3728 KB |
Output is correct |
49 |
Correct |
489 ms |
3460 KB |
Output is correct |
50 |
Correct |
281 ms |
2668 KB |
Output is correct |
51 |
Correct |
265 ms |
2412 KB |
Output is correct |
52 |
Correct |
628 ms |
4344 KB |
Output is correct |
53 |
Correct |
462 ms |
3856 KB |
Output is correct |
54 |
Correct |
656 ms |
4736 KB |
Output is correct |
55 |
Execution timed out |
1088 ms |
7628 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |