#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=505;
bitset<N*N>dp;
int arr[N],vis[N];
bool ans[N*N];
vector<int>s[N*4];
int n,sum,total;
void upd(int l,int r,int v,int nd,int x,int y){
if(l>y or x>r)
return;
if(l<=x and y<=r){
s[nd].pb(v);
return;
}
int mid=(x+y)>>1;
upd(l,r,v,nd<<1,x,mid);
upd(l,r,v,nd<<1|1,mid+1,y);
}
void solve(int nd,int x,int y,bitset<N*N>tmp){
tr(it,s[nd])
tmp=tmp|(tmp<<(*it));
if(x==y){
if(vis[arr[x]])
return;
vis[arr[x]]=1;
total-=arr[x];
for(int j=0;j<=sum;j++){
if(!ans[j])
continue;
if((j+total)&1){
ans[j]=0;
continue;
}
if(!tmp[(j+total)/2]){
ans[j]=0;
continue;
}
}
total+=arr[x];
return;
}
int mid=(x+y)>>1;
solve(nd<<1,x,mid,tmp);
solve(nd<<1|1,mid+1,y,tmp);
}
int main(){
//~ freopen("file.in", "r", stdin);
scanf("%d",&n);
dp[0]=1;
for(int i=1;i<=n;i++){
scanf("%d",arr+i);
dp=dp|(dp<<arr[i]);
upd(1,i-1,arr[i],1,1,n);
upd(i+1,n,arr[i],1,1,n);
sum+=arr[i];
}
if(sum&1 or !dp[sum/2]){
puts("0");
return 0;
}
for(int j=0;j<=sum;j++)
ans[j]=1;
total=sum;
dp.reset();dp[0]=1;
solve(1,1,n,dp);
int res=0;
for(int j=0;j<=sum;j++)
res+=ans[j];
printf("%d\n",res);
for(int j=0;j<=sum;j++)
if(ans[j])
printf("%d ",j);
puts("");
return 0;
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:66:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
bootfall.cpp:69:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",arr+i);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2692 KB |
Output is correct |
2 |
Correct |
0 ms |
2820 KB |
Output is correct |
3 |
Correct |
0 ms |
2352 KB |
Output is correct |
4 |
Correct |
0 ms |
2696 KB |
Output is correct |
5 |
Correct |
0 ms |
2940 KB |
Output is correct |
6 |
Correct |
0 ms |
2816 KB |
Output is correct |
7 |
Correct |
0 ms |
2816 KB |
Output is correct |
8 |
Correct |
0 ms |
2940 KB |
Output is correct |
9 |
Correct |
0 ms |
2940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2692 KB |
Output is correct |
2 |
Correct |
0 ms |
2820 KB |
Output is correct |
3 |
Correct |
0 ms |
2352 KB |
Output is correct |
4 |
Correct |
0 ms |
2696 KB |
Output is correct |
5 |
Correct |
0 ms |
2940 KB |
Output is correct |
6 |
Correct |
0 ms |
2816 KB |
Output is correct |
7 |
Correct |
0 ms |
2816 KB |
Output is correct |
8 |
Correct |
0 ms |
2940 KB |
Output is correct |
9 |
Correct |
0 ms |
2940 KB |
Output is correct |
10 |
Correct |
3 ms |
3068 KB |
Output is correct |
11 |
Correct |
3 ms |
3064 KB |
Output is correct |
12 |
Correct |
3 ms |
3068 KB |
Output is correct |
13 |
Correct |
3 ms |
3068 KB |
Output is correct |
14 |
Correct |
0 ms |
3068 KB |
Output is correct |
15 |
Correct |
3 ms |
3064 KB |
Output is correct |
16 |
Correct |
3 ms |
3068 KB |
Output is correct |
17 |
Correct |
3 ms |
3068 KB |
Output is correct |
18 |
Correct |
3 ms |
3064 KB |
Output is correct |
19 |
Correct |
3 ms |
3068 KB |
Output is correct |
20 |
Correct |
3 ms |
3064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2692 KB |
Output is correct |
2 |
Correct |
0 ms |
2820 KB |
Output is correct |
3 |
Correct |
0 ms |
2352 KB |
Output is correct |
4 |
Correct |
0 ms |
2696 KB |
Output is correct |
5 |
Correct |
0 ms |
2940 KB |
Output is correct |
6 |
Correct |
0 ms |
2816 KB |
Output is correct |
7 |
Correct |
0 ms |
2816 KB |
Output is correct |
8 |
Correct |
0 ms |
2940 KB |
Output is correct |
9 |
Correct |
0 ms |
2940 KB |
Output is correct |
10 |
Correct |
3 ms |
3068 KB |
Output is correct |
11 |
Correct |
3 ms |
3064 KB |
Output is correct |
12 |
Correct |
3 ms |
3068 KB |
Output is correct |
13 |
Correct |
3 ms |
3068 KB |
Output is correct |
14 |
Correct |
0 ms |
3068 KB |
Output is correct |
15 |
Correct |
3 ms |
3064 KB |
Output is correct |
16 |
Correct |
3 ms |
3068 KB |
Output is correct |
17 |
Correct |
3 ms |
3068 KB |
Output is correct |
18 |
Correct |
3 ms |
3064 KB |
Output is correct |
19 |
Correct |
3 ms |
3068 KB |
Output is correct |
20 |
Correct |
3 ms |
3064 KB |
Output is correct |
21 |
Correct |
9 ms |
3188 KB |
Output is correct |
22 |
Correct |
9 ms |
3320 KB |
Output is correct |
23 |
Correct |
6 ms |
3188 KB |
Output is correct |
24 |
Correct |
13 ms |
3320 KB |
Output is correct |
25 |
Correct |
13 ms |
3316 KB |
Output is correct |
26 |
Correct |
13 ms |
3320 KB |
Output is correct |
27 |
Correct |
16 ms |
3320 KB |
Output is correct |
28 |
Correct |
16 ms |
3316 KB |
Output is correct |
29 |
Correct |
16 ms |
3312 KB |
Output is correct |
30 |
Correct |
13 ms |
3316 KB |
Output is correct |
31 |
Correct |
16 ms |
3320 KB |
Output is correct |
32 |
Correct |
16 ms |
3316 KB |
Output is correct |
33 |
Correct |
13 ms |
3312 KB |
Output is correct |
34 |
Correct |
16 ms |
3320 KB |
Output is correct |
35 |
Correct |
16 ms |
3320 KB |
Output is correct |
36 |
Correct |
16 ms |
3316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2692 KB |
Output is correct |
2 |
Correct |
0 ms |
2820 KB |
Output is correct |
3 |
Correct |
0 ms |
2352 KB |
Output is correct |
4 |
Correct |
0 ms |
2696 KB |
Output is correct |
5 |
Correct |
0 ms |
2940 KB |
Output is correct |
6 |
Correct |
0 ms |
2816 KB |
Output is correct |
7 |
Correct |
0 ms |
2816 KB |
Output is correct |
8 |
Correct |
0 ms |
2940 KB |
Output is correct |
9 |
Correct |
0 ms |
2940 KB |
Output is correct |
10 |
Correct |
3 ms |
3068 KB |
Output is correct |
11 |
Correct |
3 ms |
3064 KB |
Output is correct |
12 |
Correct |
3 ms |
3068 KB |
Output is correct |
13 |
Correct |
3 ms |
3068 KB |
Output is correct |
14 |
Correct |
0 ms |
3068 KB |
Output is correct |
15 |
Correct |
3 ms |
3064 KB |
Output is correct |
16 |
Correct |
3 ms |
3068 KB |
Output is correct |
17 |
Correct |
3 ms |
3068 KB |
Output is correct |
18 |
Correct |
3 ms |
3064 KB |
Output is correct |
19 |
Correct |
3 ms |
3068 KB |
Output is correct |
20 |
Correct |
3 ms |
3064 KB |
Output is correct |
21 |
Correct |
9 ms |
3188 KB |
Output is correct |
22 |
Correct |
9 ms |
3320 KB |
Output is correct |
23 |
Correct |
6 ms |
3188 KB |
Output is correct |
24 |
Correct |
13 ms |
3320 KB |
Output is correct |
25 |
Correct |
13 ms |
3316 KB |
Output is correct |
26 |
Correct |
13 ms |
3320 KB |
Output is correct |
27 |
Correct |
16 ms |
3320 KB |
Output is correct |
28 |
Correct |
16 ms |
3316 KB |
Output is correct |
29 |
Correct |
16 ms |
3312 KB |
Output is correct |
30 |
Correct |
13 ms |
3316 KB |
Output is correct |
31 |
Correct |
16 ms |
3320 KB |
Output is correct |
32 |
Correct |
16 ms |
3316 KB |
Output is correct |
33 |
Correct |
13 ms |
3312 KB |
Output is correct |
34 |
Correct |
16 ms |
3320 KB |
Output is correct |
35 |
Correct |
16 ms |
3320 KB |
Output is correct |
36 |
Correct |
16 ms |
3316 KB |
Output is correct |
37 |
Correct |
39 ms |
3440 KB |
Output is correct |
38 |
Correct |
36 ms |
3444 KB |
Output is correct |
39 |
Correct |
43 ms |
3440 KB |
Output is correct |
40 |
Correct |
53 ms |
3568 KB |
Output is correct |
41 |
Correct |
49 ms |
3564 KB |
Output is correct |
42 |
Correct |
49 ms |
3444 KB |
Output is correct |
43 |
Correct |
43 ms |
3444 KB |
Output is correct |
44 |
Correct |
46 ms |
3444 KB |
Output is correct |
45 |
Correct |
46 ms |
3440 KB |
Output is correct |
46 |
Correct |
49 ms |
3564 KB |
Output is correct |
47 |
Correct |
46 ms |
3440 KB |
Output is correct |
48 |
Correct |
49 ms |
3444 KB |
Output is correct |
49 |
Correct |
43 ms |
3440 KB |
Output is correct |
50 |
Correct |
53 ms |
3444 KB |
Output is correct |
51 |
Correct |
3 ms |
2352 KB |
Output is correct |
52 |
Correct |
49 ms |
3568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2692 KB |
Output is correct |
2 |
Correct |
0 ms |
2820 KB |
Output is correct |
3 |
Correct |
0 ms |
2352 KB |
Output is correct |
4 |
Correct |
0 ms |
2696 KB |
Output is correct |
5 |
Correct |
0 ms |
2940 KB |
Output is correct |
6 |
Correct |
0 ms |
2816 KB |
Output is correct |
7 |
Correct |
0 ms |
2816 KB |
Output is correct |
8 |
Correct |
0 ms |
2940 KB |
Output is correct |
9 |
Correct |
0 ms |
2940 KB |
Output is correct |
10 |
Correct |
3 ms |
3068 KB |
Output is correct |
11 |
Correct |
3 ms |
3064 KB |
Output is correct |
12 |
Correct |
3 ms |
3068 KB |
Output is correct |
13 |
Correct |
3 ms |
3068 KB |
Output is correct |
14 |
Correct |
0 ms |
3068 KB |
Output is correct |
15 |
Correct |
3 ms |
3064 KB |
Output is correct |
16 |
Correct |
3 ms |
3068 KB |
Output is correct |
17 |
Correct |
3 ms |
3068 KB |
Output is correct |
18 |
Correct |
3 ms |
3064 KB |
Output is correct |
19 |
Correct |
3 ms |
3068 KB |
Output is correct |
20 |
Correct |
3 ms |
3064 KB |
Output is correct |
21 |
Correct |
9 ms |
3188 KB |
Output is correct |
22 |
Correct |
9 ms |
3320 KB |
Output is correct |
23 |
Correct |
6 ms |
3188 KB |
Output is correct |
24 |
Correct |
13 ms |
3320 KB |
Output is correct |
25 |
Correct |
13 ms |
3316 KB |
Output is correct |
26 |
Correct |
13 ms |
3320 KB |
Output is correct |
27 |
Correct |
16 ms |
3320 KB |
Output is correct |
28 |
Correct |
16 ms |
3316 KB |
Output is correct |
29 |
Correct |
16 ms |
3312 KB |
Output is correct |
30 |
Correct |
13 ms |
3316 KB |
Output is correct |
31 |
Correct |
16 ms |
3320 KB |
Output is correct |
32 |
Correct |
16 ms |
3316 KB |
Output is correct |
33 |
Correct |
13 ms |
3312 KB |
Output is correct |
34 |
Correct |
16 ms |
3320 KB |
Output is correct |
35 |
Correct |
16 ms |
3320 KB |
Output is correct |
36 |
Correct |
16 ms |
3316 KB |
Output is correct |
37 |
Correct |
39 ms |
3440 KB |
Output is correct |
38 |
Correct |
36 ms |
3444 KB |
Output is correct |
39 |
Correct |
43 ms |
3440 KB |
Output is correct |
40 |
Correct |
53 ms |
3568 KB |
Output is correct |
41 |
Correct |
49 ms |
3564 KB |
Output is correct |
42 |
Correct |
49 ms |
3444 KB |
Output is correct |
43 |
Correct |
43 ms |
3444 KB |
Output is correct |
44 |
Correct |
46 ms |
3444 KB |
Output is correct |
45 |
Correct |
46 ms |
3440 KB |
Output is correct |
46 |
Correct |
49 ms |
3564 KB |
Output is correct |
47 |
Correct |
46 ms |
3440 KB |
Output is correct |
48 |
Correct |
49 ms |
3444 KB |
Output is correct |
49 |
Correct |
43 ms |
3440 KB |
Output is correct |
50 |
Correct |
53 ms |
3444 KB |
Output is correct |
51 |
Correct |
3 ms |
2352 KB |
Output is correct |
52 |
Correct |
49 ms |
3568 KB |
Output is correct |
53 |
Correct |
63 ms |
3568 KB |
Output is correct |
54 |
Correct |
76 ms |
3568 KB |
Output is correct |
55 |
Correct |
66 ms |
3564 KB |
Output is correct |
56 |
Correct |
66 ms |
3568 KB |
Output is correct |
57 |
Correct |
83 ms |
3568 KB |
Output is correct |
58 |
Correct |
83 ms |
3568 KB |
Output is correct |
59 |
Correct |
76 ms |
3564 KB |
Output is correct |
60 |
Correct |
9 ms |
2352 KB |
Output is correct |
61 |
Correct |
83 ms |
3568 KB |
Output is correct |
62 |
Correct |
66 ms |
3568 KB |
Output is correct |
63 |
Correct |
76 ms |
3564 KB |
Output is correct |
64 |
Correct |
69 ms |
3564 KB |
Output is correct |
65 |
Correct |
56 ms |
3564 KB |
Output is correct |
66 |
Correct |
63 ms |
3572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2692 KB |
Output is correct |
2 |
Correct |
0 ms |
2820 KB |
Output is correct |
3 |
Correct |
0 ms |
2352 KB |
Output is correct |
4 |
Correct |
0 ms |
2696 KB |
Output is correct |
5 |
Correct |
0 ms |
2940 KB |
Output is correct |
6 |
Correct |
0 ms |
2816 KB |
Output is correct |
7 |
Correct |
0 ms |
2816 KB |
Output is correct |
8 |
Correct |
0 ms |
2940 KB |
Output is correct |
9 |
Correct |
0 ms |
2940 KB |
Output is correct |
10 |
Correct |
3 ms |
3068 KB |
Output is correct |
11 |
Correct |
3 ms |
3064 KB |
Output is correct |
12 |
Correct |
3 ms |
3068 KB |
Output is correct |
13 |
Correct |
3 ms |
3068 KB |
Output is correct |
14 |
Correct |
0 ms |
3068 KB |
Output is correct |
15 |
Correct |
3 ms |
3064 KB |
Output is correct |
16 |
Correct |
3 ms |
3068 KB |
Output is correct |
17 |
Correct |
3 ms |
3068 KB |
Output is correct |
18 |
Correct |
3 ms |
3064 KB |
Output is correct |
19 |
Correct |
3 ms |
3068 KB |
Output is correct |
20 |
Correct |
3 ms |
3064 KB |
Output is correct |
21 |
Correct |
9 ms |
3188 KB |
Output is correct |
22 |
Correct |
9 ms |
3320 KB |
Output is correct |
23 |
Correct |
6 ms |
3188 KB |
Output is correct |
24 |
Correct |
13 ms |
3320 KB |
Output is correct |
25 |
Correct |
13 ms |
3316 KB |
Output is correct |
26 |
Correct |
13 ms |
3320 KB |
Output is correct |
27 |
Correct |
16 ms |
3320 KB |
Output is correct |
28 |
Correct |
16 ms |
3316 KB |
Output is correct |
29 |
Correct |
16 ms |
3312 KB |
Output is correct |
30 |
Correct |
13 ms |
3316 KB |
Output is correct |
31 |
Correct |
16 ms |
3320 KB |
Output is correct |
32 |
Correct |
16 ms |
3316 KB |
Output is correct |
33 |
Correct |
13 ms |
3312 KB |
Output is correct |
34 |
Correct |
16 ms |
3320 KB |
Output is correct |
35 |
Correct |
16 ms |
3320 KB |
Output is correct |
36 |
Correct |
16 ms |
3316 KB |
Output is correct |
37 |
Correct |
39 ms |
3440 KB |
Output is correct |
38 |
Correct |
36 ms |
3444 KB |
Output is correct |
39 |
Correct |
43 ms |
3440 KB |
Output is correct |
40 |
Correct |
53 ms |
3568 KB |
Output is correct |
41 |
Correct |
49 ms |
3564 KB |
Output is correct |
42 |
Correct |
49 ms |
3444 KB |
Output is correct |
43 |
Correct |
43 ms |
3444 KB |
Output is correct |
44 |
Correct |
46 ms |
3444 KB |
Output is correct |
45 |
Correct |
46 ms |
3440 KB |
Output is correct |
46 |
Correct |
49 ms |
3564 KB |
Output is correct |
47 |
Correct |
46 ms |
3440 KB |
Output is correct |
48 |
Correct |
49 ms |
3444 KB |
Output is correct |
49 |
Correct |
43 ms |
3440 KB |
Output is correct |
50 |
Correct |
53 ms |
3444 KB |
Output is correct |
51 |
Correct |
3 ms |
2352 KB |
Output is correct |
52 |
Correct |
49 ms |
3568 KB |
Output is correct |
53 |
Correct |
63 ms |
3568 KB |
Output is correct |
54 |
Correct |
76 ms |
3568 KB |
Output is correct |
55 |
Correct |
66 ms |
3564 KB |
Output is correct |
56 |
Correct |
66 ms |
3568 KB |
Output is correct |
57 |
Correct |
83 ms |
3568 KB |
Output is correct |
58 |
Correct |
83 ms |
3568 KB |
Output is correct |
59 |
Correct |
76 ms |
3564 KB |
Output is correct |
60 |
Correct |
9 ms |
2352 KB |
Output is correct |
61 |
Correct |
83 ms |
3568 KB |
Output is correct |
62 |
Correct |
66 ms |
3568 KB |
Output is correct |
63 |
Correct |
76 ms |
3564 KB |
Output is correct |
64 |
Correct |
69 ms |
3564 KB |
Output is correct |
65 |
Correct |
56 ms |
3564 KB |
Output is correct |
66 |
Correct |
63 ms |
3572 KB |
Output is correct |
67 |
Correct |
99 ms |
3564 KB |
Output is correct |
68 |
Correct |
9 ms |
2352 KB |
Output is correct |
69 |
Correct |
126 ms |
3568 KB |
Output is correct |
70 |
Correct |
153 ms |
3572 KB |
Output is correct |
71 |
Correct |
153 ms |
3564 KB |
Output is correct |
72 |
Correct |
156 ms |
3564 KB |
Output is correct |
73 |
Correct |
153 ms |
3568 KB |
Output is correct |
74 |
Correct |
126 ms |
3564 KB |
Output is correct |
75 |
Correct |
139 ms |
3568 KB |
Output is correct |
76 |
Correct |
106 ms |
3568 KB |
Output is correct |
77 |
Correct |
123 ms |
3568 KB |
Output is correct |