#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt")
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 510;
const int C = mxn*mxn;
int mod = 998244353;
int arr[mxn];
int dp[C];
int del[C];
int n;
int sum = 0;
bitset<C> able;
inline ll mad(int a,int b){
a += b;
return a>=mod?a-mod:a;
}
inline ll mub(int a,int b){
return mad(a,mod-b);
}
inline bool check(int now,int tsum){
if(sum&1)return false;
if(!dp[sum>>1])return false;
if(tsum&1)return false;
if(tsum/2<now)return false;
if(!del[tsum>>1])return false;
return true;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
dp[0] = 1;
for(int i = 1;i<=n;i++){
cin>>arr[i];
sum += arr[i];
for(int j = C-1;j>=arr[i];j--)dp[j] =mad(dp[j],dp[j-arr[i]]);
}
vector<int> ans;
able.set();
for(int i = 1;i<=n;i++){
for(int j = 0;j<C;j++)del[j] = dp[j];
for(int j = arr[i];j<C;j++)del[j] = mub(del[j],del[j-arr[i]]);
for(int j = 1;j<=sum;j++){
if(!check(j,sum-arr[i]+j))able[j] = false;
}
}
for(int j = 1;j<=sum;j++)if(able[j])ans.push_back(j);
memset(dp,0,sizeof(dp));
mod = 712271227;
dp[0] = 1;
able.set();
for(int i = 1;i<=n;i++){
for(int j = 0;j<C;j++)del[j] = dp[j];
for(int j = arr[i];j<C;j++)del[j] = mub(del[j],del[j-arr[i]]);
for(int j = 1;j<=sum;j++){
if(!check(j,sum-arr[i]+j))able[j] = false;
}
}
for(int j = 1;j<=sum;j++)if(able[j])ans.push_back(j);
memset(dp,0,sizeof(dp));
mod = 1e9+7;
dp[0] = 1;
able.set();
for(int i = 1;i<=n;i++){
for(int j = 0;j<C;j++)del[j] = dp[j];
for(int j = arr[i];j<C;j++)del[j] = mub(del[j],del[j-arr[i]]);
for(int j = 1;j<=sum;j++){
if(!check(j,sum-arr[i]+j))able[j] = false;
}
}
for(int j = 1;j<=sum;j++)if(able[j])ans.push_back(j);
/*
for(int i = 0;i<=10;i++)cout<<dp[i]<<' ';cout<<endl;
cout<<sum<<endl;
cout<<endl;
for(int i = 1;i<=n;i++){
for(int j = 0;j<=10;j++)cout<<del[i][j]<<' ';cout<<endl;
}
*/
sort(ans.begin(),ans.end());
ans.erase(unique(ans.begin(),ans.end()),ans.end());
cout<<ans.size()<<'\n';
for(auto &i:ans)cout<<i<<' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2396 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Correct |
6 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
7 ms |
2396 KB |
Output is correct |
6 |
Correct |
7 ms |
2520 KB |
Output is correct |
7 |
Correct |
4 ms |
2528 KB |
Output is correct |
8 |
Correct |
6 ms |
2392 KB |
Output is correct |
9 |
Correct |
5 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2396 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Correct |
6 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
7 ms |
2396 KB |
Output is correct |
6 |
Correct |
7 ms |
2520 KB |
Output is correct |
7 |
Correct |
4 ms |
2528 KB |
Output is correct |
8 |
Correct |
6 ms |
2392 KB |
Output is correct |
9 |
Correct |
5 ms |
2392 KB |
Output is correct |
10 |
Correct |
20 ms |
2520 KB |
Output is correct |
11 |
Correct |
36 ms |
2520 KB |
Output is correct |
12 |
Correct |
25 ms |
2392 KB |
Output is correct |
13 |
Correct |
28 ms |
2392 KB |
Output is correct |
14 |
Correct |
28 ms |
2396 KB |
Output is correct |
15 |
Correct |
34 ms |
2396 KB |
Output is correct |
16 |
Correct |
38 ms |
2392 KB |
Output is correct |
17 |
Correct |
19 ms |
2396 KB |
Output is correct |
18 |
Correct |
24 ms |
2648 KB |
Output is correct |
19 |
Correct |
28 ms |
2396 KB |
Output is correct |
20 |
Correct |
17 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2396 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Correct |
6 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
7 ms |
2396 KB |
Output is correct |
6 |
Correct |
7 ms |
2520 KB |
Output is correct |
7 |
Correct |
4 ms |
2528 KB |
Output is correct |
8 |
Correct |
6 ms |
2392 KB |
Output is correct |
9 |
Correct |
5 ms |
2392 KB |
Output is correct |
10 |
Correct |
20 ms |
2520 KB |
Output is correct |
11 |
Correct |
36 ms |
2520 KB |
Output is correct |
12 |
Correct |
25 ms |
2392 KB |
Output is correct |
13 |
Correct |
28 ms |
2392 KB |
Output is correct |
14 |
Correct |
28 ms |
2396 KB |
Output is correct |
15 |
Correct |
34 ms |
2396 KB |
Output is correct |
16 |
Correct |
38 ms |
2392 KB |
Output is correct |
17 |
Correct |
19 ms |
2396 KB |
Output is correct |
18 |
Correct |
24 ms |
2648 KB |
Output is correct |
19 |
Correct |
28 ms |
2396 KB |
Output is correct |
20 |
Correct |
17 ms |
2396 KB |
Output is correct |
21 |
Correct |
34 ms |
2396 KB |
Output is correct |
22 |
Correct |
41 ms |
2652 KB |
Output is correct |
23 |
Correct |
29 ms |
2396 KB |
Output is correct |
24 |
Correct |
55 ms |
2540 KB |
Output is correct |
25 |
Correct |
34 ms |
2396 KB |
Output is correct |
26 |
Correct |
36 ms |
2392 KB |
Output is correct |
27 |
Correct |
36 ms |
2396 KB |
Output is correct |
28 |
Correct |
36 ms |
2504 KB |
Output is correct |
29 |
Correct |
36 ms |
2512 KB |
Output is correct |
30 |
Correct |
49 ms |
2652 KB |
Output is correct |
31 |
Correct |
36 ms |
2592 KB |
Output is correct |
32 |
Correct |
54 ms |
2532 KB |
Output is correct |
33 |
Correct |
37 ms |
2396 KB |
Output is correct |
34 |
Correct |
38 ms |
2396 KB |
Output is correct |
35 |
Correct |
37 ms |
2396 KB |
Output is correct |
36 |
Correct |
60 ms |
2528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2396 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Correct |
6 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
7 ms |
2396 KB |
Output is correct |
6 |
Correct |
7 ms |
2520 KB |
Output is correct |
7 |
Correct |
4 ms |
2528 KB |
Output is correct |
8 |
Correct |
6 ms |
2392 KB |
Output is correct |
9 |
Correct |
5 ms |
2392 KB |
Output is correct |
10 |
Correct |
20 ms |
2520 KB |
Output is correct |
11 |
Correct |
36 ms |
2520 KB |
Output is correct |
12 |
Correct |
25 ms |
2392 KB |
Output is correct |
13 |
Correct |
28 ms |
2392 KB |
Output is correct |
14 |
Correct |
28 ms |
2396 KB |
Output is correct |
15 |
Correct |
34 ms |
2396 KB |
Output is correct |
16 |
Correct |
38 ms |
2392 KB |
Output is correct |
17 |
Correct |
19 ms |
2396 KB |
Output is correct |
18 |
Correct |
24 ms |
2648 KB |
Output is correct |
19 |
Correct |
28 ms |
2396 KB |
Output is correct |
20 |
Correct |
17 ms |
2396 KB |
Output is correct |
21 |
Correct |
34 ms |
2396 KB |
Output is correct |
22 |
Correct |
41 ms |
2652 KB |
Output is correct |
23 |
Correct |
29 ms |
2396 KB |
Output is correct |
24 |
Correct |
55 ms |
2540 KB |
Output is correct |
25 |
Correct |
34 ms |
2396 KB |
Output is correct |
26 |
Correct |
36 ms |
2392 KB |
Output is correct |
27 |
Correct |
36 ms |
2396 KB |
Output is correct |
28 |
Correct |
36 ms |
2504 KB |
Output is correct |
29 |
Correct |
36 ms |
2512 KB |
Output is correct |
30 |
Correct |
49 ms |
2652 KB |
Output is correct |
31 |
Correct |
36 ms |
2592 KB |
Output is correct |
32 |
Correct |
54 ms |
2532 KB |
Output is correct |
33 |
Correct |
37 ms |
2396 KB |
Output is correct |
34 |
Correct |
38 ms |
2396 KB |
Output is correct |
35 |
Correct |
37 ms |
2396 KB |
Output is correct |
36 |
Correct |
60 ms |
2528 KB |
Output is correct |
37 |
Correct |
81 ms |
2644 KB |
Output is correct |
38 |
Correct |
82 ms |
2608 KB |
Output is correct |
39 |
Correct |
161 ms |
2384 KB |
Output is correct |
40 |
Correct |
142 ms |
2496 KB |
Output is correct |
41 |
Correct |
188 ms |
2488 KB |
Output is correct |
42 |
Correct |
131 ms |
2516 KB |
Output is correct |
43 |
Correct |
136 ms |
2640 KB |
Output is correct |
44 |
Correct |
146 ms |
2732 KB |
Output is correct |
45 |
Correct |
145 ms |
2640 KB |
Output is correct |
46 |
Correct |
142 ms |
2392 KB |
Output is correct |
47 |
Correct |
132 ms |
2640 KB |
Output is correct |
48 |
Correct |
150 ms |
2736 KB |
Output is correct |
49 |
Correct |
153 ms |
2384 KB |
Output is correct |
50 |
Correct |
137 ms |
2640 KB |
Output is correct |
51 |
Correct |
135 ms |
2640 KB |
Output is correct |
52 |
Correct |
175 ms |
2896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2396 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Correct |
6 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
7 ms |
2396 KB |
Output is correct |
6 |
Correct |
7 ms |
2520 KB |
Output is correct |
7 |
Correct |
4 ms |
2528 KB |
Output is correct |
8 |
Correct |
6 ms |
2392 KB |
Output is correct |
9 |
Correct |
5 ms |
2392 KB |
Output is correct |
10 |
Correct |
20 ms |
2520 KB |
Output is correct |
11 |
Correct |
36 ms |
2520 KB |
Output is correct |
12 |
Correct |
25 ms |
2392 KB |
Output is correct |
13 |
Correct |
28 ms |
2392 KB |
Output is correct |
14 |
Correct |
28 ms |
2396 KB |
Output is correct |
15 |
Correct |
34 ms |
2396 KB |
Output is correct |
16 |
Correct |
38 ms |
2392 KB |
Output is correct |
17 |
Correct |
19 ms |
2396 KB |
Output is correct |
18 |
Correct |
24 ms |
2648 KB |
Output is correct |
19 |
Correct |
28 ms |
2396 KB |
Output is correct |
20 |
Correct |
17 ms |
2396 KB |
Output is correct |
21 |
Correct |
34 ms |
2396 KB |
Output is correct |
22 |
Correct |
41 ms |
2652 KB |
Output is correct |
23 |
Correct |
29 ms |
2396 KB |
Output is correct |
24 |
Correct |
55 ms |
2540 KB |
Output is correct |
25 |
Correct |
34 ms |
2396 KB |
Output is correct |
26 |
Correct |
36 ms |
2392 KB |
Output is correct |
27 |
Correct |
36 ms |
2396 KB |
Output is correct |
28 |
Correct |
36 ms |
2504 KB |
Output is correct |
29 |
Correct |
36 ms |
2512 KB |
Output is correct |
30 |
Correct |
49 ms |
2652 KB |
Output is correct |
31 |
Correct |
36 ms |
2592 KB |
Output is correct |
32 |
Correct |
54 ms |
2532 KB |
Output is correct |
33 |
Correct |
37 ms |
2396 KB |
Output is correct |
34 |
Correct |
38 ms |
2396 KB |
Output is correct |
35 |
Correct |
37 ms |
2396 KB |
Output is correct |
36 |
Correct |
60 ms |
2528 KB |
Output is correct |
37 |
Correct |
81 ms |
2644 KB |
Output is correct |
38 |
Correct |
82 ms |
2608 KB |
Output is correct |
39 |
Correct |
161 ms |
2384 KB |
Output is correct |
40 |
Correct |
142 ms |
2496 KB |
Output is correct |
41 |
Correct |
188 ms |
2488 KB |
Output is correct |
42 |
Correct |
131 ms |
2516 KB |
Output is correct |
43 |
Correct |
136 ms |
2640 KB |
Output is correct |
44 |
Correct |
146 ms |
2732 KB |
Output is correct |
45 |
Correct |
145 ms |
2640 KB |
Output is correct |
46 |
Correct |
142 ms |
2392 KB |
Output is correct |
47 |
Correct |
132 ms |
2640 KB |
Output is correct |
48 |
Correct |
150 ms |
2736 KB |
Output is correct |
49 |
Correct |
153 ms |
2384 KB |
Output is correct |
50 |
Correct |
137 ms |
2640 KB |
Output is correct |
51 |
Correct |
135 ms |
2640 KB |
Output is correct |
52 |
Correct |
175 ms |
2896 KB |
Output is correct |
53 |
Correct |
162 ms |
2720 KB |
Output is correct |
54 |
Correct |
199 ms |
2736 KB |
Output is correct |
55 |
Correct |
292 ms |
2880 KB |
Output is correct |
56 |
Correct |
171 ms |
2760 KB |
Output is correct |
57 |
Correct |
294 ms |
3248 KB |
Output is correct |
58 |
Incorrect |
228 ms |
2900 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2396 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Correct |
6 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
7 ms |
2396 KB |
Output is correct |
6 |
Correct |
7 ms |
2520 KB |
Output is correct |
7 |
Correct |
4 ms |
2528 KB |
Output is correct |
8 |
Correct |
6 ms |
2392 KB |
Output is correct |
9 |
Correct |
5 ms |
2392 KB |
Output is correct |
10 |
Correct |
20 ms |
2520 KB |
Output is correct |
11 |
Correct |
36 ms |
2520 KB |
Output is correct |
12 |
Correct |
25 ms |
2392 KB |
Output is correct |
13 |
Correct |
28 ms |
2392 KB |
Output is correct |
14 |
Correct |
28 ms |
2396 KB |
Output is correct |
15 |
Correct |
34 ms |
2396 KB |
Output is correct |
16 |
Correct |
38 ms |
2392 KB |
Output is correct |
17 |
Correct |
19 ms |
2396 KB |
Output is correct |
18 |
Correct |
24 ms |
2648 KB |
Output is correct |
19 |
Correct |
28 ms |
2396 KB |
Output is correct |
20 |
Correct |
17 ms |
2396 KB |
Output is correct |
21 |
Correct |
34 ms |
2396 KB |
Output is correct |
22 |
Correct |
41 ms |
2652 KB |
Output is correct |
23 |
Correct |
29 ms |
2396 KB |
Output is correct |
24 |
Correct |
55 ms |
2540 KB |
Output is correct |
25 |
Correct |
34 ms |
2396 KB |
Output is correct |
26 |
Correct |
36 ms |
2392 KB |
Output is correct |
27 |
Correct |
36 ms |
2396 KB |
Output is correct |
28 |
Correct |
36 ms |
2504 KB |
Output is correct |
29 |
Correct |
36 ms |
2512 KB |
Output is correct |
30 |
Correct |
49 ms |
2652 KB |
Output is correct |
31 |
Correct |
36 ms |
2592 KB |
Output is correct |
32 |
Correct |
54 ms |
2532 KB |
Output is correct |
33 |
Correct |
37 ms |
2396 KB |
Output is correct |
34 |
Correct |
38 ms |
2396 KB |
Output is correct |
35 |
Correct |
37 ms |
2396 KB |
Output is correct |
36 |
Correct |
60 ms |
2528 KB |
Output is correct |
37 |
Correct |
81 ms |
2644 KB |
Output is correct |
38 |
Correct |
82 ms |
2608 KB |
Output is correct |
39 |
Correct |
161 ms |
2384 KB |
Output is correct |
40 |
Correct |
142 ms |
2496 KB |
Output is correct |
41 |
Correct |
188 ms |
2488 KB |
Output is correct |
42 |
Correct |
131 ms |
2516 KB |
Output is correct |
43 |
Correct |
136 ms |
2640 KB |
Output is correct |
44 |
Correct |
146 ms |
2732 KB |
Output is correct |
45 |
Correct |
145 ms |
2640 KB |
Output is correct |
46 |
Correct |
142 ms |
2392 KB |
Output is correct |
47 |
Correct |
132 ms |
2640 KB |
Output is correct |
48 |
Correct |
150 ms |
2736 KB |
Output is correct |
49 |
Correct |
153 ms |
2384 KB |
Output is correct |
50 |
Correct |
137 ms |
2640 KB |
Output is correct |
51 |
Correct |
135 ms |
2640 KB |
Output is correct |
52 |
Correct |
175 ms |
2896 KB |
Output is correct |
53 |
Correct |
162 ms |
2720 KB |
Output is correct |
54 |
Correct |
199 ms |
2736 KB |
Output is correct |
55 |
Correct |
292 ms |
2880 KB |
Output is correct |
56 |
Correct |
171 ms |
2760 KB |
Output is correct |
57 |
Correct |
294 ms |
3248 KB |
Output is correct |
58 |
Incorrect |
228 ms |
2900 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |