#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>
mt19937 seed(time(NULL));
#define rnd(l,r) uniform_int_distribution<int>(l,r)(seed)
const int mxn = 510;
const int C = mxn*mxn/2;
int mod = 998244353;
int arr[mxn];
int dp[C];
int del[C];
int n;
int sum = 0;
bitset<C> able;
set<int> ans;
inline int mad(int a,int b){
a += b;
return a>=mod?a-mod:a;
}
inline int 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(now+now>tsum)return false;
if(!del[tsum>>1])return false;
return true;
}
inline void relax(int tar){
mod = tar;
memset(dp,0,sizeof(dp));
dp[0] = 1;
able.set();
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[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.insert(j);
}
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];
}
int lim = CLOCKS_PER_SEC*0.9;
int st = clock();
relax((int)1e9+7);
relax((int)712271227);
relax((int)1e8+7);
//relax(113);
relax(998244353);
relax(101010111);
const int inf = 1e9+10;
//cout<<rnd(0,inf);
//if(n>350)while(clock()-st<=lim)relax(rnd(0,inf));
/*
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;
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:69:6: warning: unused variable 'lim' [-Wunused-variable]
69 | int lim = CLOCKS_PER_SEC*0.9;
| ^~~
bootfall.cpp:70:6: warning: unused variable 'st' [-Wunused-variable]
70 | int st = clock();
| ^~
bootfall.cpp:78:12: warning: unused variable 'inf' [-Wunused-variable]
78 | const int inf = 1e9+10;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1368 KB |
Output is correct |
2 |
Correct |
7 ms |
1368 KB |
Output is correct |
3 |
Correct |
5 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
1372 KB |
Output is correct |
5 |
Correct |
7 ms |
1368 KB |
Output is correct |
6 |
Correct |
7 ms |
1624 KB |
Output is correct |
7 |
Correct |
4 ms |
1500 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
5 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1368 KB |
Output is correct |
2 |
Correct |
7 ms |
1368 KB |
Output is correct |
3 |
Correct |
5 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
1372 KB |
Output is correct |
5 |
Correct |
7 ms |
1368 KB |
Output is correct |
6 |
Correct |
7 ms |
1624 KB |
Output is correct |
7 |
Correct |
4 ms |
1500 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
5 ms |
1372 KB |
Output is correct |
10 |
Correct |
21 ms |
1496 KB |
Output is correct |
11 |
Correct |
34 ms |
1476 KB |
Output is correct |
12 |
Correct |
25 ms |
1496 KB |
Output is correct |
13 |
Correct |
27 ms |
1372 KB |
Output is correct |
14 |
Correct |
29 ms |
1372 KB |
Output is correct |
15 |
Correct |
33 ms |
1372 KB |
Output is correct |
16 |
Correct |
36 ms |
1372 KB |
Output is correct |
17 |
Correct |
18 ms |
1496 KB |
Output is correct |
18 |
Correct |
23 ms |
1372 KB |
Output is correct |
19 |
Correct |
27 ms |
1372 KB |
Output is correct |
20 |
Correct |
19 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1368 KB |
Output is correct |
2 |
Correct |
7 ms |
1368 KB |
Output is correct |
3 |
Correct |
5 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
1372 KB |
Output is correct |
5 |
Correct |
7 ms |
1368 KB |
Output is correct |
6 |
Correct |
7 ms |
1624 KB |
Output is correct |
7 |
Correct |
4 ms |
1500 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
5 ms |
1372 KB |
Output is correct |
10 |
Correct |
21 ms |
1496 KB |
Output is correct |
11 |
Correct |
34 ms |
1476 KB |
Output is correct |
12 |
Correct |
25 ms |
1496 KB |
Output is correct |
13 |
Correct |
27 ms |
1372 KB |
Output is correct |
14 |
Correct |
29 ms |
1372 KB |
Output is correct |
15 |
Correct |
33 ms |
1372 KB |
Output is correct |
16 |
Correct |
36 ms |
1372 KB |
Output is correct |
17 |
Correct |
18 ms |
1496 KB |
Output is correct |
18 |
Correct |
23 ms |
1372 KB |
Output is correct |
19 |
Correct |
27 ms |
1372 KB |
Output is correct |
20 |
Correct |
19 ms |
1372 KB |
Output is correct |
21 |
Correct |
40 ms |
1560 KB |
Output is correct |
22 |
Correct |
45 ms |
1372 KB |
Output is correct |
23 |
Correct |
31 ms |
1368 KB |
Output is correct |
24 |
Correct |
60 ms |
1488 KB |
Output is correct |
25 |
Correct |
46 ms |
1628 KB |
Output is correct |
26 |
Correct |
48 ms |
1624 KB |
Output is correct |
27 |
Correct |
53 ms |
1500 KB |
Output is correct |
28 |
Correct |
50 ms |
1368 KB |
Output is correct |
29 |
Correct |
49 ms |
1620 KB |
Output is correct |
30 |
Correct |
55 ms |
1624 KB |
Output is correct |
31 |
Correct |
47 ms |
1624 KB |
Output is correct |
32 |
Correct |
60 ms |
1368 KB |
Output is correct |
33 |
Correct |
52 ms |
1368 KB |
Output is correct |
34 |
Correct |
52 ms |
1372 KB |
Output is correct |
35 |
Correct |
50 ms |
1372 KB |
Output is correct |
36 |
Correct |
65 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1368 KB |
Output is correct |
2 |
Correct |
7 ms |
1368 KB |
Output is correct |
3 |
Correct |
5 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
1372 KB |
Output is correct |
5 |
Correct |
7 ms |
1368 KB |
Output is correct |
6 |
Correct |
7 ms |
1624 KB |
Output is correct |
7 |
Correct |
4 ms |
1500 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
5 ms |
1372 KB |
Output is correct |
10 |
Correct |
21 ms |
1496 KB |
Output is correct |
11 |
Correct |
34 ms |
1476 KB |
Output is correct |
12 |
Correct |
25 ms |
1496 KB |
Output is correct |
13 |
Correct |
27 ms |
1372 KB |
Output is correct |
14 |
Correct |
29 ms |
1372 KB |
Output is correct |
15 |
Correct |
33 ms |
1372 KB |
Output is correct |
16 |
Correct |
36 ms |
1372 KB |
Output is correct |
17 |
Correct |
18 ms |
1496 KB |
Output is correct |
18 |
Correct |
23 ms |
1372 KB |
Output is correct |
19 |
Correct |
27 ms |
1372 KB |
Output is correct |
20 |
Correct |
19 ms |
1372 KB |
Output is correct |
21 |
Correct |
40 ms |
1560 KB |
Output is correct |
22 |
Correct |
45 ms |
1372 KB |
Output is correct |
23 |
Correct |
31 ms |
1368 KB |
Output is correct |
24 |
Correct |
60 ms |
1488 KB |
Output is correct |
25 |
Correct |
46 ms |
1628 KB |
Output is correct |
26 |
Correct |
48 ms |
1624 KB |
Output is correct |
27 |
Correct |
53 ms |
1500 KB |
Output is correct |
28 |
Correct |
50 ms |
1368 KB |
Output is correct |
29 |
Correct |
49 ms |
1620 KB |
Output is correct |
30 |
Correct |
55 ms |
1624 KB |
Output is correct |
31 |
Correct |
47 ms |
1624 KB |
Output is correct |
32 |
Correct |
60 ms |
1368 KB |
Output is correct |
33 |
Correct |
52 ms |
1368 KB |
Output is correct |
34 |
Correct |
52 ms |
1372 KB |
Output is correct |
35 |
Correct |
50 ms |
1372 KB |
Output is correct |
36 |
Correct |
65 ms |
1372 KB |
Output is correct |
37 |
Correct |
106 ms |
1920 KB |
Output is correct |
38 |
Correct |
105 ms |
1876 KB |
Output is correct |
39 |
Correct |
251 ms |
1476 KB |
Output is correct |
40 |
Correct |
176 ms |
2224 KB |
Output is correct |
41 |
Correct |
296 ms |
1476 KB |
Output is correct |
42 |
Correct |
162 ms |
2132 KB |
Output is correct |
43 |
Correct |
174 ms |
2644 KB |
Output is correct |
44 |
Correct |
183 ms |
2708 KB |
Output is correct |
45 |
Correct |
185 ms |
2752 KB |
Output is correct |
46 |
Correct |
192 ms |
1380 KB |
Output is correct |
47 |
Correct |
161 ms |
2384 KB |
Output is correct |
48 |
Correct |
198 ms |
2388 KB |
Output is correct |
49 |
Correct |
221 ms |
1696 KB |
Output is correct |
50 |
Correct |
169 ms |
2128 KB |
Output is correct |
51 |
Correct |
177 ms |
1472 KB |
Output is correct |
52 |
Correct |
228 ms |
2900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1368 KB |
Output is correct |
2 |
Correct |
7 ms |
1368 KB |
Output is correct |
3 |
Correct |
5 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
1372 KB |
Output is correct |
5 |
Correct |
7 ms |
1368 KB |
Output is correct |
6 |
Correct |
7 ms |
1624 KB |
Output is correct |
7 |
Correct |
4 ms |
1500 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
5 ms |
1372 KB |
Output is correct |
10 |
Correct |
21 ms |
1496 KB |
Output is correct |
11 |
Correct |
34 ms |
1476 KB |
Output is correct |
12 |
Correct |
25 ms |
1496 KB |
Output is correct |
13 |
Correct |
27 ms |
1372 KB |
Output is correct |
14 |
Correct |
29 ms |
1372 KB |
Output is correct |
15 |
Correct |
33 ms |
1372 KB |
Output is correct |
16 |
Correct |
36 ms |
1372 KB |
Output is correct |
17 |
Correct |
18 ms |
1496 KB |
Output is correct |
18 |
Correct |
23 ms |
1372 KB |
Output is correct |
19 |
Correct |
27 ms |
1372 KB |
Output is correct |
20 |
Correct |
19 ms |
1372 KB |
Output is correct |
21 |
Correct |
40 ms |
1560 KB |
Output is correct |
22 |
Correct |
45 ms |
1372 KB |
Output is correct |
23 |
Correct |
31 ms |
1368 KB |
Output is correct |
24 |
Correct |
60 ms |
1488 KB |
Output is correct |
25 |
Correct |
46 ms |
1628 KB |
Output is correct |
26 |
Correct |
48 ms |
1624 KB |
Output is correct |
27 |
Correct |
53 ms |
1500 KB |
Output is correct |
28 |
Correct |
50 ms |
1368 KB |
Output is correct |
29 |
Correct |
49 ms |
1620 KB |
Output is correct |
30 |
Correct |
55 ms |
1624 KB |
Output is correct |
31 |
Correct |
47 ms |
1624 KB |
Output is correct |
32 |
Correct |
60 ms |
1368 KB |
Output is correct |
33 |
Correct |
52 ms |
1368 KB |
Output is correct |
34 |
Correct |
52 ms |
1372 KB |
Output is correct |
35 |
Correct |
50 ms |
1372 KB |
Output is correct |
36 |
Correct |
65 ms |
1372 KB |
Output is correct |
37 |
Correct |
106 ms |
1920 KB |
Output is correct |
38 |
Correct |
105 ms |
1876 KB |
Output is correct |
39 |
Correct |
251 ms |
1476 KB |
Output is correct |
40 |
Correct |
176 ms |
2224 KB |
Output is correct |
41 |
Correct |
296 ms |
1476 KB |
Output is correct |
42 |
Correct |
162 ms |
2132 KB |
Output is correct |
43 |
Correct |
174 ms |
2644 KB |
Output is correct |
44 |
Correct |
183 ms |
2708 KB |
Output is correct |
45 |
Correct |
185 ms |
2752 KB |
Output is correct |
46 |
Correct |
192 ms |
1380 KB |
Output is correct |
47 |
Correct |
161 ms |
2384 KB |
Output is correct |
48 |
Correct |
198 ms |
2388 KB |
Output is correct |
49 |
Correct |
221 ms |
1696 KB |
Output is correct |
50 |
Correct |
169 ms |
2128 KB |
Output is correct |
51 |
Correct |
177 ms |
1472 KB |
Output is correct |
52 |
Correct |
228 ms |
2900 KB |
Output is correct |
53 |
Correct |
201 ms |
2640 KB |
Output is correct |
54 |
Correct |
258 ms |
2760 KB |
Output is correct |
55 |
Correct |
359 ms |
3920 KB |
Output is correct |
56 |
Correct |
220 ms |
2896 KB |
Output is correct |
57 |
Correct |
370 ms |
4188 KB |
Output is correct |
58 |
Correct |
269 ms |
2900 KB |
Output is correct |
59 |
Correct |
289 ms |
3408 KB |
Output is correct |
60 |
Correct |
321 ms |
1372 KB |
Output is correct |
61 |
Correct |
305 ms |
3576 KB |
Output is correct |
62 |
Correct |
300 ms |
3900 KB |
Output is correct |
63 |
Correct |
312 ms |
3792 KB |
Output is correct |
64 |
Correct |
315 ms |
4180 KB |
Output is correct |
65 |
Correct |
283 ms |
1372 KB |
Output is correct |
66 |
Correct |
285 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1368 KB |
Output is correct |
2 |
Correct |
7 ms |
1368 KB |
Output is correct |
3 |
Correct |
5 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
1372 KB |
Output is correct |
5 |
Correct |
7 ms |
1368 KB |
Output is correct |
6 |
Correct |
7 ms |
1624 KB |
Output is correct |
7 |
Correct |
4 ms |
1500 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
5 ms |
1372 KB |
Output is correct |
10 |
Correct |
21 ms |
1496 KB |
Output is correct |
11 |
Correct |
34 ms |
1476 KB |
Output is correct |
12 |
Correct |
25 ms |
1496 KB |
Output is correct |
13 |
Correct |
27 ms |
1372 KB |
Output is correct |
14 |
Correct |
29 ms |
1372 KB |
Output is correct |
15 |
Correct |
33 ms |
1372 KB |
Output is correct |
16 |
Correct |
36 ms |
1372 KB |
Output is correct |
17 |
Correct |
18 ms |
1496 KB |
Output is correct |
18 |
Correct |
23 ms |
1372 KB |
Output is correct |
19 |
Correct |
27 ms |
1372 KB |
Output is correct |
20 |
Correct |
19 ms |
1372 KB |
Output is correct |
21 |
Correct |
40 ms |
1560 KB |
Output is correct |
22 |
Correct |
45 ms |
1372 KB |
Output is correct |
23 |
Correct |
31 ms |
1368 KB |
Output is correct |
24 |
Correct |
60 ms |
1488 KB |
Output is correct |
25 |
Correct |
46 ms |
1628 KB |
Output is correct |
26 |
Correct |
48 ms |
1624 KB |
Output is correct |
27 |
Correct |
53 ms |
1500 KB |
Output is correct |
28 |
Correct |
50 ms |
1368 KB |
Output is correct |
29 |
Correct |
49 ms |
1620 KB |
Output is correct |
30 |
Correct |
55 ms |
1624 KB |
Output is correct |
31 |
Correct |
47 ms |
1624 KB |
Output is correct |
32 |
Correct |
60 ms |
1368 KB |
Output is correct |
33 |
Correct |
52 ms |
1368 KB |
Output is correct |
34 |
Correct |
52 ms |
1372 KB |
Output is correct |
35 |
Correct |
50 ms |
1372 KB |
Output is correct |
36 |
Correct |
65 ms |
1372 KB |
Output is correct |
37 |
Correct |
106 ms |
1920 KB |
Output is correct |
38 |
Correct |
105 ms |
1876 KB |
Output is correct |
39 |
Correct |
251 ms |
1476 KB |
Output is correct |
40 |
Correct |
176 ms |
2224 KB |
Output is correct |
41 |
Correct |
296 ms |
1476 KB |
Output is correct |
42 |
Correct |
162 ms |
2132 KB |
Output is correct |
43 |
Correct |
174 ms |
2644 KB |
Output is correct |
44 |
Correct |
183 ms |
2708 KB |
Output is correct |
45 |
Correct |
185 ms |
2752 KB |
Output is correct |
46 |
Correct |
192 ms |
1380 KB |
Output is correct |
47 |
Correct |
161 ms |
2384 KB |
Output is correct |
48 |
Correct |
198 ms |
2388 KB |
Output is correct |
49 |
Correct |
221 ms |
1696 KB |
Output is correct |
50 |
Correct |
169 ms |
2128 KB |
Output is correct |
51 |
Correct |
177 ms |
1472 KB |
Output is correct |
52 |
Correct |
228 ms |
2900 KB |
Output is correct |
53 |
Correct |
201 ms |
2640 KB |
Output is correct |
54 |
Correct |
258 ms |
2760 KB |
Output is correct |
55 |
Correct |
359 ms |
3920 KB |
Output is correct |
56 |
Correct |
220 ms |
2896 KB |
Output is correct |
57 |
Correct |
370 ms |
4188 KB |
Output is correct |
58 |
Correct |
269 ms |
2900 KB |
Output is correct |
59 |
Correct |
289 ms |
3408 KB |
Output is correct |
60 |
Correct |
321 ms |
1372 KB |
Output is correct |
61 |
Correct |
305 ms |
3576 KB |
Output is correct |
62 |
Correct |
300 ms |
3900 KB |
Output is correct |
63 |
Correct |
312 ms |
3792 KB |
Output is correct |
64 |
Correct |
315 ms |
4180 KB |
Output is correct |
65 |
Correct |
283 ms |
1372 KB |
Output is correct |
66 |
Correct |
285 ms |
1620 KB |
Output is correct |
67 |
Correct |
350 ms |
3544 KB |
Output is correct |
68 |
Correct |
747 ms |
1616 KB |
Output is correct |
69 |
Incorrect |
212 ms |
4616 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |