#include <bits/stdc++.h>
using namespace std;
#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-1)/2;
int mod = 998244353;
int arr[mxn];
int dp[C];
int del[mxn][C];
int n;
int sum = 0;
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){
if(sum&1)return false;
if(!dp[sum>>1])return false;
int tsum = sum+now;
for(int i = 1;i<=n;i++){
tsum -= arr[i];
if(tsum&1)return false;
if(tsum/2<now)return false;
if(!del[i][tsum>>1])return false;
tsum += arr[i];
}
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]]);
}
for(int i = 1;i<=n;i++){
for(int j = 0;j<C;j++)del[i][j] = dp[j];
for(int j = arr[i];j<C;j++)del[i][j] = mub(del[i][j],del[i][j-arr[i]]);
}
vector<int> ans;
for(int i = 1;i<C;i++){
if(check(i))ans.push_back(i);
}
vector<int> ans2;
mod = 1e9+7;
memset(dp,0,sizeof(dp));
dp[0] = 1;
for(int i = 1;i<=n;i++){
for(int j = C-1;j>=arr[i];j--)dp[j] =mad(dp[j],dp[j-arr[i]]);
}
for(int i = 1;i<=n;i++){
for(int j = 0;j<C;j++)del[i][j] = dp[j];
for(int j = arr[i];j<C;j++)del[i][j] = mub(del[i][j],del[i][j-arr[i]]);
}
for(auto &i:ans){
if(check(i))ans2.push_back(i);
}
swap(ans,ans2);
ans2.clear();
/*
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;
}
*/
cout<<ans.size()<<'\n';
for(auto &i:ans)cout<<i<<' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
4 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
2908 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
7 ms |
9052 KB |
Output is correct |
6 |
Correct |
5 ms |
7000 KB |
Output is correct |
7 |
Correct |
5 ms |
4956 KB |
Output is correct |
8 |
Correct |
7 ms |
9304 KB |
Output is correct |
9 |
Correct |
6 ms |
7000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
4 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
2908 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
7 ms |
9052 KB |
Output is correct |
6 |
Correct |
5 ms |
7000 KB |
Output is correct |
7 |
Correct |
5 ms |
4956 KB |
Output is correct |
8 |
Correct |
7 ms |
9304 KB |
Output is correct |
9 |
Correct |
6 ms |
7000 KB |
Output is correct |
10 |
Correct |
17 ms |
17496 KB |
Output is correct |
11 |
Correct |
20 ms |
17244 KB |
Output is correct |
12 |
Correct |
17 ms |
17244 KB |
Output is correct |
13 |
Correct |
17 ms |
15312 KB |
Output is correct |
14 |
Correct |
16 ms |
17244 KB |
Output is correct |
15 |
Correct |
19 ms |
17380 KB |
Output is correct |
16 |
Correct |
20 ms |
17240 KB |
Output is correct |
17 |
Correct |
11 ms |
11096 KB |
Output is correct |
18 |
Correct |
15 ms |
15196 KB |
Output is correct |
19 |
Correct |
17 ms |
15304 KB |
Output is correct |
20 |
Correct |
17 ms |
17384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
4 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
2908 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
7 ms |
9052 KB |
Output is correct |
6 |
Correct |
5 ms |
7000 KB |
Output is correct |
7 |
Correct |
5 ms |
4956 KB |
Output is correct |
8 |
Correct |
7 ms |
9304 KB |
Output is correct |
9 |
Correct |
6 ms |
7000 KB |
Output is correct |
10 |
Correct |
17 ms |
17496 KB |
Output is correct |
11 |
Correct |
20 ms |
17244 KB |
Output is correct |
12 |
Correct |
17 ms |
17244 KB |
Output is correct |
13 |
Correct |
17 ms |
15312 KB |
Output is correct |
14 |
Correct |
16 ms |
17244 KB |
Output is correct |
15 |
Correct |
19 ms |
17380 KB |
Output is correct |
16 |
Correct |
20 ms |
17240 KB |
Output is correct |
17 |
Correct |
11 ms |
11096 KB |
Output is correct |
18 |
Correct |
15 ms |
15196 KB |
Output is correct |
19 |
Correct |
17 ms |
15304 KB |
Output is correct |
20 |
Correct |
17 ms |
17384 KB |
Output is correct |
21 |
Correct |
37 ms |
35860 KB |
Output is correct |
22 |
Correct |
42 ms |
39976 KB |
Output is correct |
23 |
Correct |
30 ms |
27484 KB |
Output is correct |
24 |
Correct |
55 ms |
50232 KB |
Output is correct |
25 |
Correct |
54 ms |
50256 KB |
Output is correct |
26 |
Correct |
58 ms |
52272 KB |
Output is correct |
27 |
Correct |
56 ms |
52216 KB |
Output is correct |
28 |
Correct |
55 ms |
52216 KB |
Output is correct |
29 |
Correct |
55 ms |
52060 KB |
Output is correct |
30 |
Correct |
55 ms |
52224 KB |
Output is correct |
31 |
Correct |
57 ms |
52308 KB |
Output is correct |
32 |
Correct |
56 ms |
52048 KB |
Output is correct |
33 |
Correct |
55 ms |
52060 KB |
Output is correct |
34 |
Correct |
58 ms |
52160 KB |
Output is correct |
35 |
Correct |
60 ms |
52220 KB |
Output is correct |
36 |
Correct |
61 ms |
52060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
4 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
2908 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
7 ms |
9052 KB |
Output is correct |
6 |
Correct |
5 ms |
7000 KB |
Output is correct |
7 |
Correct |
5 ms |
4956 KB |
Output is correct |
8 |
Correct |
7 ms |
9304 KB |
Output is correct |
9 |
Correct |
6 ms |
7000 KB |
Output is correct |
10 |
Correct |
17 ms |
17496 KB |
Output is correct |
11 |
Correct |
20 ms |
17244 KB |
Output is correct |
12 |
Correct |
17 ms |
17244 KB |
Output is correct |
13 |
Correct |
17 ms |
15312 KB |
Output is correct |
14 |
Correct |
16 ms |
17244 KB |
Output is correct |
15 |
Correct |
19 ms |
17380 KB |
Output is correct |
16 |
Correct |
20 ms |
17240 KB |
Output is correct |
17 |
Correct |
11 ms |
11096 KB |
Output is correct |
18 |
Correct |
15 ms |
15196 KB |
Output is correct |
19 |
Correct |
17 ms |
15304 KB |
Output is correct |
20 |
Correct |
17 ms |
17384 KB |
Output is correct |
21 |
Correct |
37 ms |
35860 KB |
Output is correct |
22 |
Correct |
42 ms |
39976 KB |
Output is correct |
23 |
Correct |
30 ms |
27484 KB |
Output is correct |
24 |
Correct |
55 ms |
50232 KB |
Output is correct |
25 |
Correct |
54 ms |
50256 KB |
Output is correct |
26 |
Correct |
58 ms |
52272 KB |
Output is correct |
27 |
Correct |
56 ms |
52216 KB |
Output is correct |
28 |
Correct |
55 ms |
52216 KB |
Output is correct |
29 |
Correct |
55 ms |
52060 KB |
Output is correct |
30 |
Correct |
55 ms |
52224 KB |
Output is correct |
31 |
Correct |
57 ms |
52308 KB |
Output is correct |
32 |
Correct |
56 ms |
52048 KB |
Output is correct |
33 |
Correct |
55 ms |
52060 KB |
Output is correct |
34 |
Correct |
58 ms |
52160 KB |
Output is correct |
35 |
Correct |
60 ms |
52220 KB |
Output is correct |
36 |
Correct |
61 ms |
52060 KB |
Output is correct |
37 |
Correct |
121 ms |
103508 KB |
Output is correct |
38 |
Correct |
117 ms |
103620 KB |
Output is correct |
39 |
Correct |
140 ms |
127936 KB |
Output is correct |
40 |
Correct |
165 ms |
140728 KB |
Output is correct |
41 |
Correct |
145 ms |
140416 KB |
Output is correct |
42 |
Correct |
154 ms |
130640 KB |
Output is correct |
43 |
Correct |
156 ms |
126548 KB |
Output is correct |
44 |
Correct |
159 ms |
128592 KB |
Output is correct |
45 |
Correct |
165 ms |
130752 KB |
Output is correct |
46 |
Correct |
144 ms |
140372 KB |
Output is correct |
47 |
Correct |
150 ms |
130384 KB |
Output is correct |
48 |
Correct |
154 ms |
130384 KB |
Output is correct |
49 |
Correct |
144 ms |
130476 KB |
Output is correct |
50 |
Correct |
151 ms |
130388 KB |
Output is correct |
51 |
Correct |
138 ms |
130132 KB |
Output is correct |
52 |
Correct |
175 ms |
140884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
4 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
2908 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
7 ms |
9052 KB |
Output is correct |
6 |
Correct |
5 ms |
7000 KB |
Output is correct |
7 |
Correct |
5 ms |
4956 KB |
Output is correct |
8 |
Correct |
7 ms |
9304 KB |
Output is correct |
9 |
Correct |
6 ms |
7000 KB |
Output is correct |
10 |
Correct |
17 ms |
17496 KB |
Output is correct |
11 |
Correct |
20 ms |
17244 KB |
Output is correct |
12 |
Correct |
17 ms |
17244 KB |
Output is correct |
13 |
Correct |
17 ms |
15312 KB |
Output is correct |
14 |
Correct |
16 ms |
17244 KB |
Output is correct |
15 |
Correct |
19 ms |
17380 KB |
Output is correct |
16 |
Correct |
20 ms |
17240 KB |
Output is correct |
17 |
Correct |
11 ms |
11096 KB |
Output is correct |
18 |
Correct |
15 ms |
15196 KB |
Output is correct |
19 |
Correct |
17 ms |
15304 KB |
Output is correct |
20 |
Correct |
17 ms |
17384 KB |
Output is correct |
21 |
Correct |
37 ms |
35860 KB |
Output is correct |
22 |
Correct |
42 ms |
39976 KB |
Output is correct |
23 |
Correct |
30 ms |
27484 KB |
Output is correct |
24 |
Correct |
55 ms |
50232 KB |
Output is correct |
25 |
Correct |
54 ms |
50256 KB |
Output is correct |
26 |
Correct |
58 ms |
52272 KB |
Output is correct |
27 |
Correct |
56 ms |
52216 KB |
Output is correct |
28 |
Correct |
55 ms |
52216 KB |
Output is correct |
29 |
Correct |
55 ms |
52060 KB |
Output is correct |
30 |
Correct |
55 ms |
52224 KB |
Output is correct |
31 |
Correct |
57 ms |
52308 KB |
Output is correct |
32 |
Correct |
56 ms |
52048 KB |
Output is correct |
33 |
Correct |
55 ms |
52060 KB |
Output is correct |
34 |
Correct |
58 ms |
52160 KB |
Output is correct |
35 |
Correct |
60 ms |
52220 KB |
Output is correct |
36 |
Correct |
61 ms |
52060 KB |
Output is correct |
37 |
Correct |
121 ms |
103508 KB |
Output is correct |
38 |
Correct |
117 ms |
103620 KB |
Output is correct |
39 |
Correct |
140 ms |
127936 KB |
Output is correct |
40 |
Correct |
165 ms |
140728 KB |
Output is correct |
41 |
Correct |
145 ms |
140416 KB |
Output is correct |
42 |
Correct |
154 ms |
130640 KB |
Output is correct |
43 |
Correct |
156 ms |
126548 KB |
Output is correct |
44 |
Correct |
159 ms |
128592 KB |
Output is correct |
45 |
Correct |
165 ms |
130752 KB |
Output is correct |
46 |
Correct |
144 ms |
140372 KB |
Output is correct |
47 |
Correct |
150 ms |
130384 KB |
Output is correct |
48 |
Correct |
154 ms |
130384 KB |
Output is correct |
49 |
Correct |
144 ms |
130476 KB |
Output is correct |
50 |
Correct |
151 ms |
130388 KB |
Output is correct |
51 |
Correct |
138 ms |
130132 KB |
Output is correct |
52 |
Correct |
175 ms |
140884 KB |
Output is correct |
53 |
Correct |
186 ms |
155220 KB |
Output is correct |
54 |
Correct |
224 ms |
179964 KB |
Output is correct |
55 |
Correct |
255 ms |
180392 KB |
Output is correct |
56 |
Correct |
198 ms |
157268 KB |
Output is correct |
57 |
Correct |
254 ms |
180308 KB |
Output is correct |
58 |
Incorrect |
227 ms |
180064 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
4 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
2908 KB |
Output is correct |
4 |
Correct |
3 ms |
4956 KB |
Output is correct |
5 |
Correct |
7 ms |
9052 KB |
Output is correct |
6 |
Correct |
5 ms |
7000 KB |
Output is correct |
7 |
Correct |
5 ms |
4956 KB |
Output is correct |
8 |
Correct |
7 ms |
9304 KB |
Output is correct |
9 |
Correct |
6 ms |
7000 KB |
Output is correct |
10 |
Correct |
17 ms |
17496 KB |
Output is correct |
11 |
Correct |
20 ms |
17244 KB |
Output is correct |
12 |
Correct |
17 ms |
17244 KB |
Output is correct |
13 |
Correct |
17 ms |
15312 KB |
Output is correct |
14 |
Correct |
16 ms |
17244 KB |
Output is correct |
15 |
Correct |
19 ms |
17380 KB |
Output is correct |
16 |
Correct |
20 ms |
17240 KB |
Output is correct |
17 |
Correct |
11 ms |
11096 KB |
Output is correct |
18 |
Correct |
15 ms |
15196 KB |
Output is correct |
19 |
Correct |
17 ms |
15304 KB |
Output is correct |
20 |
Correct |
17 ms |
17384 KB |
Output is correct |
21 |
Correct |
37 ms |
35860 KB |
Output is correct |
22 |
Correct |
42 ms |
39976 KB |
Output is correct |
23 |
Correct |
30 ms |
27484 KB |
Output is correct |
24 |
Correct |
55 ms |
50232 KB |
Output is correct |
25 |
Correct |
54 ms |
50256 KB |
Output is correct |
26 |
Correct |
58 ms |
52272 KB |
Output is correct |
27 |
Correct |
56 ms |
52216 KB |
Output is correct |
28 |
Correct |
55 ms |
52216 KB |
Output is correct |
29 |
Correct |
55 ms |
52060 KB |
Output is correct |
30 |
Correct |
55 ms |
52224 KB |
Output is correct |
31 |
Correct |
57 ms |
52308 KB |
Output is correct |
32 |
Correct |
56 ms |
52048 KB |
Output is correct |
33 |
Correct |
55 ms |
52060 KB |
Output is correct |
34 |
Correct |
58 ms |
52160 KB |
Output is correct |
35 |
Correct |
60 ms |
52220 KB |
Output is correct |
36 |
Correct |
61 ms |
52060 KB |
Output is correct |
37 |
Correct |
121 ms |
103508 KB |
Output is correct |
38 |
Correct |
117 ms |
103620 KB |
Output is correct |
39 |
Correct |
140 ms |
127936 KB |
Output is correct |
40 |
Correct |
165 ms |
140728 KB |
Output is correct |
41 |
Correct |
145 ms |
140416 KB |
Output is correct |
42 |
Correct |
154 ms |
130640 KB |
Output is correct |
43 |
Correct |
156 ms |
126548 KB |
Output is correct |
44 |
Correct |
159 ms |
128592 KB |
Output is correct |
45 |
Correct |
165 ms |
130752 KB |
Output is correct |
46 |
Correct |
144 ms |
140372 KB |
Output is correct |
47 |
Correct |
150 ms |
130384 KB |
Output is correct |
48 |
Correct |
154 ms |
130384 KB |
Output is correct |
49 |
Correct |
144 ms |
130476 KB |
Output is correct |
50 |
Correct |
151 ms |
130388 KB |
Output is correct |
51 |
Correct |
138 ms |
130132 KB |
Output is correct |
52 |
Correct |
175 ms |
140884 KB |
Output is correct |
53 |
Correct |
186 ms |
155220 KB |
Output is correct |
54 |
Correct |
224 ms |
179964 KB |
Output is correct |
55 |
Correct |
255 ms |
180392 KB |
Output is correct |
56 |
Correct |
198 ms |
157268 KB |
Output is correct |
57 |
Correct |
254 ms |
180308 KB |
Output is correct |
58 |
Incorrect |
227 ms |
180064 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |