#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 = 550;
const int mod = 998244353;
int arr[mxn];
int dp[mxn*mxn];
int del[mxn][mxn*mxn];
int n;
int sum = 0;
inline ll mad(ll a,ll b){
a += b;
return a>=mod?a-mod:a;
}
inline ll mub(ll a,ll 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 = mxn*mxn-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<mxn*mxn;j++)del[i][j] = dp[j];
for(int j = arr[i];j<mxn*mxn;j++)del[i][j] = mub(del[i][j],del[i][j-arr[i]]);
}
vector<int> ans;
for(int i = 1;i<mxn*mxn;i++){
if(check(i))ans.push_back(i);
}
/*
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 |
7 ms |
7772 KB |
Output is correct |
2 |
Correct |
7 ms |
9856 KB |
Output is correct |
3 |
Correct |
5 ms |
7772 KB |
Output is correct |
4 |
Correct |
5 ms |
7772 KB |
Output is correct |
5 |
Correct |
12 ms |
18012 KB |
Output is correct |
6 |
Correct |
8 ms |
13916 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
12 ms |
18012 KB |
Output is correct |
9 |
Correct |
10 ms |
15964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7772 KB |
Output is correct |
2 |
Correct |
7 ms |
9856 KB |
Output is correct |
3 |
Correct |
5 ms |
7772 KB |
Output is correct |
4 |
Correct |
5 ms |
7772 KB |
Output is correct |
5 |
Correct |
12 ms |
18012 KB |
Output is correct |
6 |
Correct |
8 ms |
13916 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
12 ms |
18012 KB |
Output is correct |
9 |
Correct |
10 ms |
15964 KB |
Output is correct |
10 |
Correct |
26 ms |
38484 KB |
Output is correct |
11 |
Correct |
30 ms |
38484 KB |
Output is correct |
12 |
Correct |
27 ms |
38492 KB |
Output is correct |
13 |
Correct |
25 ms |
34428 KB |
Output is correct |
14 |
Correct |
25 ms |
36476 KB |
Output is correct |
15 |
Correct |
28 ms |
36436 KB |
Output is correct |
16 |
Correct |
34 ms |
38492 KB |
Output is correct |
17 |
Correct |
17 ms |
24196 KB |
Output is correct |
18 |
Correct |
22 ms |
32336 KB |
Output is correct |
19 |
Correct |
24 ms |
34412 KB |
Output is correct |
20 |
Correct |
26 ms |
38492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7772 KB |
Output is correct |
2 |
Correct |
7 ms |
9856 KB |
Output is correct |
3 |
Correct |
5 ms |
7772 KB |
Output is correct |
4 |
Correct |
5 ms |
7772 KB |
Output is correct |
5 |
Correct |
12 ms |
18012 KB |
Output is correct |
6 |
Correct |
8 ms |
13916 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
12 ms |
18012 KB |
Output is correct |
9 |
Correct |
10 ms |
15964 KB |
Output is correct |
10 |
Correct |
26 ms |
38484 KB |
Output is correct |
11 |
Correct |
30 ms |
38484 KB |
Output is correct |
12 |
Correct |
27 ms |
38492 KB |
Output is correct |
13 |
Correct |
25 ms |
34428 KB |
Output is correct |
14 |
Correct |
25 ms |
36476 KB |
Output is correct |
15 |
Correct |
28 ms |
36436 KB |
Output is correct |
16 |
Correct |
34 ms |
38492 KB |
Output is correct |
17 |
Correct |
17 ms |
24196 KB |
Output is correct |
18 |
Correct |
22 ms |
32336 KB |
Output is correct |
19 |
Correct |
24 ms |
34412 KB |
Output is correct |
20 |
Correct |
26 ms |
38492 KB |
Output is correct |
21 |
Correct |
56 ms |
79472 KB |
Output is correct |
22 |
Correct |
63 ms |
91752 KB |
Output is correct |
23 |
Correct |
51 ms |
63344 KB |
Output is correct |
24 |
Correct |
83 ms |
114284 KB |
Output is correct |
25 |
Correct |
80 ms |
114384 KB |
Output is correct |
26 |
Correct |
84 ms |
122612 KB |
Output is correct |
27 |
Correct |
83 ms |
122644 KB |
Output is correct |
28 |
Correct |
82 ms |
122720 KB |
Output is correct |
29 |
Correct |
82 ms |
122476 KB |
Output is correct |
30 |
Correct |
82 ms |
122452 KB |
Output is correct |
31 |
Correct |
84 ms |
122704 KB |
Output is correct |
32 |
Correct |
83 ms |
122704 KB |
Output is correct |
33 |
Correct |
82 ms |
122452 KB |
Output is correct |
34 |
Correct |
82 ms |
122448 KB |
Output is correct |
35 |
Correct |
82 ms |
122520 KB |
Output is correct |
36 |
Correct |
88 ms |
122708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7772 KB |
Output is correct |
2 |
Correct |
7 ms |
9856 KB |
Output is correct |
3 |
Correct |
5 ms |
7772 KB |
Output is correct |
4 |
Correct |
5 ms |
7772 KB |
Output is correct |
5 |
Correct |
12 ms |
18012 KB |
Output is correct |
6 |
Correct |
8 ms |
13916 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
12 ms |
18012 KB |
Output is correct |
9 |
Correct |
10 ms |
15964 KB |
Output is correct |
10 |
Correct |
26 ms |
38484 KB |
Output is correct |
11 |
Correct |
30 ms |
38484 KB |
Output is correct |
12 |
Correct |
27 ms |
38492 KB |
Output is correct |
13 |
Correct |
25 ms |
34428 KB |
Output is correct |
14 |
Correct |
25 ms |
36476 KB |
Output is correct |
15 |
Correct |
28 ms |
36436 KB |
Output is correct |
16 |
Correct |
34 ms |
38492 KB |
Output is correct |
17 |
Correct |
17 ms |
24196 KB |
Output is correct |
18 |
Correct |
22 ms |
32336 KB |
Output is correct |
19 |
Correct |
24 ms |
34412 KB |
Output is correct |
20 |
Correct |
26 ms |
38492 KB |
Output is correct |
21 |
Correct |
56 ms |
79472 KB |
Output is correct |
22 |
Correct |
63 ms |
91752 KB |
Output is correct |
23 |
Correct |
51 ms |
63344 KB |
Output is correct |
24 |
Correct |
83 ms |
114284 KB |
Output is correct |
25 |
Correct |
80 ms |
114384 KB |
Output is correct |
26 |
Correct |
84 ms |
122612 KB |
Output is correct |
27 |
Correct |
83 ms |
122644 KB |
Output is correct |
28 |
Correct |
82 ms |
122720 KB |
Output is correct |
29 |
Correct |
82 ms |
122476 KB |
Output is correct |
30 |
Correct |
82 ms |
122452 KB |
Output is correct |
31 |
Correct |
84 ms |
122704 KB |
Output is correct |
32 |
Correct |
83 ms |
122704 KB |
Output is correct |
33 |
Correct |
82 ms |
122452 KB |
Output is correct |
34 |
Correct |
82 ms |
122448 KB |
Output is correct |
35 |
Correct |
82 ms |
122520 KB |
Output is correct |
36 |
Correct |
88 ms |
122708 KB |
Output is correct |
37 |
Correct |
212 ms |
239948 KB |
Output is correct |
38 |
Correct |
168 ms |
239700 KB |
Output is correct |
39 |
Runtime error |
201 ms |
262144 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7772 KB |
Output is correct |
2 |
Correct |
7 ms |
9856 KB |
Output is correct |
3 |
Correct |
5 ms |
7772 KB |
Output is correct |
4 |
Correct |
5 ms |
7772 KB |
Output is correct |
5 |
Correct |
12 ms |
18012 KB |
Output is correct |
6 |
Correct |
8 ms |
13916 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
12 ms |
18012 KB |
Output is correct |
9 |
Correct |
10 ms |
15964 KB |
Output is correct |
10 |
Correct |
26 ms |
38484 KB |
Output is correct |
11 |
Correct |
30 ms |
38484 KB |
Output is correct |
12 |
Correct |
27 ms |
38492 KB |
Output is correct |
13 |
Correct |
25 ms |
34428 KB |
Output is correct |
14 |
Correct |
25 ms |
36476 KB |
Output is correct |
15 |
Correct |
28 ms |
36436 KB |
Output is correct |
16 |
Correct |
34 ms |
38492 KB |
Output is correct |
17 |
Correct |
17 ms |
24196 KB |
Output is correct |
18 |
Correct |
22 ms |
32336 KB |
Output is correct |
19 |
Correct |
24 ms |
34412 KB |
Output is correct |
20 |
Correct |
26 ms |
38492 KB |
Output is correct |
21 |
Correct |
56 ms |
79472 KB |
Output is correct |
22 |
Correct |
63 ms |
91752 KB |
Output is correct |
23 |
Correct |
51 ms |
63344 KB |
Output is correct |
24 |
Correct |
83 ms |
114284 KB |
Output is correct |
25 |
Correct |
80 ms |
114384 KB |
Output is correct |
26 |
Correct |
84 ms |
122612 KB |
Output is correct |
27 |
Correct |
83 ms |
122644 KB |
Output is correct |
28 |
Correct |
82 ms |
122720 KB |
Output is correct |
29 |
Correct |
82 ms |
122476 KB |
Output is correct |
30 |
Correct |
82 ms |
122452 KB |
Output is correct |
31 |
Correct |
84 ms |
122704 KB |
Output is correct |
32 |
Correct |
83 ms |
122704 KB |
Output is correct |
33 |
Correct |
82 ms |
122452 KB |
Output is correct |
34 |
Correct |
82 ms |
122448 KB |
Output is correct |
35 |
Correct |
82 ms |
122520 KB |
Output is correct |
36 |
Correct |
88 ms |
122708 KB |
Output is correct |
37 |
Correct |
212 ms |
239948 KB |
Output is correct |
38 |
Correct |
168 ms |
239700 KB |
Output is correct |
39 |
Runtime error |
201 ms |
262144 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7772 KB |
Output is correct |
2 |
Correct |
7 ms |
9856 KB |
Output is correct |
3 |
Correct |
5 ms |
7772 KB |
Output is correct |
4 |
Correct |
5 ms |
7772 KB |
Output is correct |
5 |
Correct |
12 ms |
18012 KB |
Output is correct |
6 |
Correct |
8 ms |
13916 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
12 ms |
18012 KB |
Output is correct |
9 |
Correct |
10 ms |
15964 KB |
Output is correct |
10 |
Correct |
26 ms |
38484 KB |
Output is correct |
11 |
Correct |
30 ms |
38484 KB |
Output is correct |
12 |
Correct |
27 ms |
38492 KB |
Output is correct |
13 |
Correct |
25 ms |
34428 KB |
Output is correct |
14 |
Correct |
25 ms |
36476 KB |
Output is correct |
15 |
Correct |
28 ms |
36436 KB |
Output is correct |
16 |
Correct |
34 ms |
38492 KB |
Output is correct |
17 |
Correct |
17 ms |
24196 KB |
Output is correct |
18 |
Correct |
22 ms |
32336 KB |
Output is correct |
19 |
Correct |
24 ms |
34412 KB |
Output is correct |
20 |
Correct |
26 ms |
38492 KB |
Output is correct |
21 |
Correct |
56 ms |
79472 KB |
Output is correct |
22 |
Correct |
63 ms |
91752 KB |
Output is correct |
23 |
Correct |
51 ms |
63344 KB |
Output is correct |
24 |
Correct |
83 ms |
114284 KB |
Output is correct |
25 |
Correct |
80 ms |
114384 KB |
Output is correct |
26 |
Correct |
84 ms |
122612 KB |
Output is correct |
27 |
Correct |
83 ms |
122644 KB |
Output is correct |
28 |
Correct |
82 ms |
122720 KB |
Output is correct |
29 |
Correct |
82 ms |
122476 KB |
Output is correct |
30 |
Correct |
82 ms |
122452 KB |
Output is correct |
31 |
Correct |
84 ms |
122704 KB |
Output is correct |
32 |
Correct |
83 ms |
122704 KB |
Output is correct |
33 |
Correct |
82 ms |
122452 KB |
Output is correct |
34 |
Correct |
82 ms |
122448 KB |
Output is correct |
35 |
Correct |
82 ms |
122520 KB |
Output is correct |
36 |
Correct |
88 ms |
122708 KB |
Output is correct |
37 |
Correct |
212 ms |
239948 KB |
Output is correct |
38 |
Correct |
168 ms |
239700 KB |
Output is correct |
39 |
Runtime error |
201 ms |
262144 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |