//Dedicated to my love, ivaziva
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ar array
#define dbg(x) cerr << #x << ": " << x << "\n";
const ll mxN=503;
const ll MOD=3657500101;
ll n, a[mxN], dp[mxN*mxN][2], brM[mxN*mxN];
void add(ll& a, ll b) {
a+=b;
if(a>MOD) a-=MOD;
}
void sub(ll& a, ll b) {
a-=b;
if(a<0) a+=MOD;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
ll sum=0;
for(ll i=1; i<=n; ++i) {
cin >> a[i];
sum+=a[i];
}
// n=500;
// for(ll i=1; i<=n; ++i) {
// a[i]=500;
// sum+=a[i]; OVERFLOW!!!!
// }
for(int i=0; i<mxN*mxN; ++i) {
for(int j=0; j<2; ++j) {
dp[i][j]=0;
}
brM[i]=0;
}
dp[0][0]=1;
for(ll i=1; i<=n; ++i) {
for(ll s=mxN*mxN-1; s>=a[i]; --s) {
add(dp[s][0], dp[s-a[i]][0]);
}
}
if(sum%2==1) {
cout << 0 << "\n";
return 0;
}
if(dp[sum/2][0]==0) {
cout << 0 << "\n";
return 0;
}
vector<ll> ans;
for(ll i=1; i<=n; ++i) {
for(ll s=0; s<mxN*mxN; ++s) {
dp[s][1]=dp[s][0];
}
for(ll s=0; s<mxN*mxN-a[i]; ++s) {
sub(dp[s+a[i]][1], dp[s][1]);
}
for(ll s=0; s<mxN*mxN; ++s) {
ll get=s+sum-a[i];
if((get%2==0)&&(get/2>=s)&&(dp[get/2-s][1]>0)) {
++brM[s];
if(brM[s]==n) ans.push_back(s);
}
}
}
cout << ans.size() << "\n";
for(ll x:ans) cout << x << " ";
cout << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6236 KB |
Output is correct |
2 |
Correct |
8 ms |
6408 KB |
Output is correct |
3 |
Correct |
3 ms |
6176 KB |
Output is correct |
4 |
Correct |
6 ms |
6540 KB |
Output is correct |
5 |
Correct |
10 ms |
6236 KB |
Output is correct |
6 |
Correct |
7 ms |
6236 KB |
Output is correct |
7 |
Correct |
7 ms |
6236 KB |
Output is correct |
8 |
Correct |
10 ms |
6236 KB |
Output is correct |
9 |
Correct |
12 ms |
6404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6236 KB |
Output is correct |
2 |
Correct |
8 ms |
6408 KB |
Output is correct |
3 |
Correct |
3 ms |
6176 KB |
Output is correct |
4 |
Correct |
6 ms |
6540 KB |
Output is correct |
5 |
Correct |
10 ms |
6236 KB |
Output is correct |
6 |
Correct |
7 ms |
6236 KB |
Output is correct |
7 |
Correct |
7 ms |
6236 KB |
Output is correct |
8 |
Correct |
10 ms |
6236 KB |
Output is correct |
9 |
Correct |
12 ms |
6404 KB |
Output is correct |
10 |
Correct |
32 ms |
6232 KB |
Output is correct |
11 |
Correct |
23 ms |
6360 KB |
Output is correct |
12 |
Correct |
22 ms |
6236 KB |
Output is correct |
13 |
Correct |
30 ms |
6396 KB |
Output is correct |
14 |
Correct |
27 ms |
6492 KB |
Output is correct |
15 |
Correct |
22 ms |
6232 KB |
Output is correct |
16 |
Correct |
29 ms |
6236 KB |
Output is correct |
17 |
Correct |
14 ms |
6400 KB |
Output is correct |
18 |
Correct |
19 ms |
6488 KB |
Output is correct |
19 |
Correct |
23 ms |
6232 KB |
Output is correct |
20 |
Correct |
38 ms |
6232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6236 KB |
Output is correct |
2 |
Correct |
8 ms |
6408 KB |
Output is correct |
3 |
Correct |
3 ms |
6176 KB |
Output is correct |
4 |
Correct |
6 ms |
6540 KB |
Output is correct |
5 |
Correct |
10 ms |
6236 KB |
Output is correct |
6 |
Correct |
7 ms |
6236 KB |
Output is correct |
7 |
Correct |
7 ms |
6236 KB |
Output is correct |
8 |
Correct |
10 ms |
6236 KB |
Output is correct |
9 |
Correct |
12 ms |
6404 KB |
Output is correct |
10 |
Correct |
32 ms |
6232 KB |
Output is correct |
11 |
Correct |
23 ms |
6360 KB |
Output is correct |
12 |
Correct |
22 ms |
6236 KB |
Output is correct |
13 |
Correct |
30 ms |
6396 KB |
Output is correct |
14 |
Correct |
27 ms |
6492 KB |
Output is correct |
15 |
Correct |
22 ms |
6232 KB |
Output is correct |
16 |
Correct |
29 ms |
6236 KB |
Output is correct |
17 |
Correct |
14 ms |
6400 KB |
Output is correct |
18 |
Correct |
19 ms |
6488 KB |
Output is correct |
19 |
Correct |
23 ms |
6232 KB |
Output is correct |
20 |
Correct |
38 ms |
6232 KB |
Output is correct |
21 |
Correct |
49 ms |
6236 KB |
Output is correct |
22 |
Correct |
58 ms |
6384 KB |
Output is correct |
23 |
Correct |
32 ms |
6396 KB |
Output is correct |
24 |
Correct |
89 ms |
6236 KB |
Output is correct |
25 |
Correct |
82 ms |
6380 KB |
Output is correct |
26 |
Correct |
69 ms |
6380 KB |
Output is correct |
27 |
Correct |
68 ms |
6376 KB |
Output is correct |
28 |
Correct |
91 ms |
6236 KB |
Output is correct |
29 |
Correct |
83 ms |
6236 KB |
Output is correct |
30 |
Correct |
69 ms |
6376 KB |
Output is correct |
31 |
Correct |
82 ms |
6236 KB |
Output is correct |
32 |
Correct |
92 ms |
6352 KB |
Output is correct |
33 |
Correct |
77 ms |
6356 KB |
Output is correct |
34 |
Correct |
73 ms |
6352 KB |
Output is correct |
35 |
Correct |
73 ms |
6492 KB |
Output is correct |
36 |
Correct |
89 ms |
6236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6236 KB |
Output is correct |
2 |
Correct |
8 ms |
6408 KB |
Output is correct |
3 |
Correct |
3 ms |
6176 KB |
Output is correct |
4 |
Correct |
6 ms |
6540 KB |
Output is correct |
5 |
Correct |
10 ms |
6236 KB |
Output is correct |
6 |
Correct |
7 ms |
6236 KB |
Output is correct |
7 |
Correct |
7 ms |
6236 KB |
Output is correct |
8 |
Correct |
10 ms |
6236 KB |
Output is correct |
9 |
Correct |
12 ms |
6404 KB |
Output is correct |
10 |
Correct |
32 ms |
6232 KB |
Output is correct |
11 |
Correct |
23 ms |
6360 KB |
Output is correct |
12 |
Correct |
22 ms |
6236 KB |
Output is correct |
13 |
Correct |
30 ms |
6396 KB |
Output is correct |
14 |
Correct |
27 ms |
6492 KB |
Output is correct |
15 |
Correct |
22 ms |
6232 KB |
Output is correct |
16 |
Correct |
29 ms |
6236 KB |
Output is correct |
17 |
Correct |
14 ms |
6400 KB |
Output is correct |
18 |
Correct |
19 ms |
6488 KB |
Output is correct |
19 |
Correct |
23 ms |
6232 KB |
Output is correct |
20 |
Correct |
38 ms |
6232 KB |
Output is correct |
21 |
Correct |
49 ms |
6236 KB |
Output is correct |
22 |
Correct |
58 ms |
6384 KB |
Output is correct |
23 |
Correct |
32 ms |
6396 KB |
Output is correct |
24 |
Correct |
89 ms |
6236 KB |
Output is correct |
25 |
Correct |
82 ms |
6380 KB |
Output is correct |
26 |
Correct |
69 ms |
6380 KB |
Output is correct |
27 |
Correct |
68 ms |
6376 KB |
Output is correct |
28 |
Correct |
91 ms |
6236 KB |
Output is correct |
29 |
Correct |
83 ms |
6236 KB |
Output is correct |
30 |
Correct |
69 ms |
6376 KB |
Output is correct |
31 |
Correct |
82 ms |
6236 KB |
Output is correct |
32 |
Correct |
92 ms |
6352 KB |
Output is correct |
33 |
Correct |
77 ms |
6356 KB |
Output is correct |
34 |
Correct |
73 ms |
6352 KB |
Output is correct |
35 |
Correct |
73 ms |
6492 KB |
Output is correct |
36 |
Correct |
89 ms |
6236 KB |
Output is correct |
37 |
Correct |
176 ms |
6636 KB |
Output is correct |
38 |
Correct |
198 ms |
6488 KB |
Output is correct |
39 |
Correct |
243 ms |
6376 KB |
Output is correct |
40 |
Correct |
227 ms |
6484 KB |
Output is correct |
41 |
Correct |
217 ms |
6376 KB |
Output is correct |
42 |
Correct |
207 ms |
6640 KB |
Output is correct |
43 |
Correct |
236 ms |
6872 KB |
Output is correct |
44 |
Correct |
263 ms |
6764 KB |
Output is correct |
45 |
Correct |
233 ms |
6768 KB |
Output is correct |
46 |
Correct |
194 ms |
6236 KB |
Output is correct |
47 |
Correct |
222 ms |
6484 KB |
Output is correct |
48 |
Correct |
244 ms |
6736 KB |
Output is correct |
49 |
Correct |
226 ms |
6484 KB |
Output is correct |
50 |
Correct |
210 ms |
6484 KB |
Output is correct |
51 |
Correct |
54 ms |
6384 KB |
Output is correct |
52 |
Correct |
308 ms |
6872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6236 KB |
Output is correct |
2 |
Correct |
8 ms |
6408 KB |
Output is correct |
3 |
Correct |
3 ms |
6176 KB |
Output is correct |
4 |
Correct |
6 ms |
6540 KB |
Output is correct |
5 |
Correct |
10 ms |
6236 KB |
Output is correct |
6 |
Correct |
7 ms |
6236 KB |
Output is correct |
7 |
Correct |
7 ms |
6236 KB |
Output is correct |
8 |
Correct |
10 ms |
6236 KB |
Output is correct |
9 |
Correct |
12 ms |
6404 KB |
Output is correct |
10 |
Correct |
32 ms |
6232 KB |
Output is correct |
11 |
Correct |
23 ms |
6360 KB |
Output is correct |
12 |
Correct |
22 ms |
6236 KB |
Output is correct |
13 |
Correct |
30 ms |
6396 KB |
Output is correct |
14 |
Correct |
27 ms |
6492 KB |
Output is correct |
15 |
Correct |
22 ms |
6232 KB |
Output is correct |
16 |
Correct |
29 ms |
6236 KB |
Output is correct |
17 |
Correct |
14 ms |
6400 KB |
Output is correct |
18 |
Correct |
19 ms |
6488 KB |
Output is correct |
19 |
Correct |
23 ms |
6232 KB |
Output is correct |
20 |
Correct |
38 ms |
6232 KB |
Output is correct |
21 |
Correct |
49 ms |
6236 KB |
Output is correct |
22 |
Correct |
58 ms |
6384 KB |
Output is correct |
23 |
Correct |
32 ms |
6396 KB |
Output is correct |
24 |
Correct |
89 ms |
6236 KB |
Output is correct |
25 |
Correct |
82 ms |
6380 KB |
Output is correct |
26 |
Correct |
69 ms |
6380 KB |
Output is correct |
27 |
Correct |
68 ms |
6376 KB |
Output is correct |
28 |
Correct |
91 ms |
6236 KB |
Output is correct |
29 |
Correct |
83 ms |
6236 KB |
Output is correct |
30 |
Correct |
69 ms |
6376 KB |
Output is correct |
31 |
Correct |
82 ms |
6236 KB |
Output is correct |
32 |
Correct |
92 ms |
6352 KB |
Output is correct |
33 |
Correct |
77 ms |
6356 KB |
Output is correct |
34 |
Correct |
73 ms |
6352 KB |
Output is correct |
35 |
Correct |
73 ms |
6492 KB |
Output is correct |
36 |
Correct |
89 ms |
6236 KB |
Output is correct |
37 |
Correct |
176 ms |
6636 KB |
Output is correct |
38 |
Correct |
198 ms |
6488 KB |
Output is correct |
39 |
Correct |
243 ms |
6376 KB |
Output is correct |
40 |
Correct |
227 ms |
6484 KB |
Output is correct |
41 |
Correct |
217 ms |
6376 KB |
Output is correct |
42 |
Correct |
207 ms |
6640 KB |
Output is correct |
43 |
Correct |
236 ms |
6872 KB |
Output is correct |
44 |
Correct |
263 ms |
6764 KB |
Output is correct |
45 |
Correct |
233 ms |
6768 KB |
Output is correct |
46 |
Correct |
194 ms |
6236 KB |
Output is correct |
47 |
Correct |
222 ms |
6484 KB |
Output is correct |
48 |
Correct |
244 ms |
6736 KB |
Output is correct |
49 |
Correct |
226 ms |
6484 KB |
Output is correct |
50 |
Correct |
210 ms |
6484 KB |
Output is correct |
51 |
Correct |
54 ms |
6384 KB |
Output is correct |
52 |
Correct |
308 ms |
6872 KB |
Output is correct |
53 |
Correct |
279 ms |
6740 KB |
Output is correct |
54 |
Correct |
394 ms |
6768 KB |
Output is correct |
55 |
Correct |
405 ms |
7128 KB |
Output is correct |
56 |
Correct |
358 ms |
6764 KB |
Output is correct |
57 |
Correct |
428 ms |
7020 KB |
Output is correct |
58 |
Correct |
384 ms |
6764 KB |
Output is correct |
59 |
Correct |
424 ms |
7024 KB |
Output is correct |
60 |
Correct |
77 ms |
6236 KB |
Output is correct |
61 |
Correct |
386 ms |
7024 KB |
Output is correct |
62 |
Correct |
387 ms |
7124 KB |
Output is correct |
63 |
Correct |
374 ms |
7020 KB |
Output is correct |
64 |
Correct |
374 ms |
7020 KB |
Output is correct |
65 |
Correct |
261 ms |
6380 KB |
Output is correct |
66 |
Correct |
255 ms |
6392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6236 KB |
Output is correct |
2 |
Correct |
8 ms |
6408 KB |
Output is correct |
3 |
Correct |
3 ms |
6176 KB |
Output is correct |
4 |
Correct |
6 ms |
6540 KB |
Output is correct |
5 |
Correct |
10 ms |
6236 KB |
Output is correct |
6 |
Correct |
7 ms |
6236 KB |
Output is correct |
7 |
Correct |
7 ms |
6236 KB |
Output is correct |
8 |
Correct |
10 ms |
6236 KB |
Output is correct |
9 |
Correct |
12 ms |
6404 KB |
Output is correct |
10 |
Correct |
32 ms |
6232 KB |
Output is correct |
11 |
Correct |
23 ms |
6360 KB |
Output is correct |
12 |
Correct |
22 ms |
6236 KB |
Output is correct |
13 |
Correct |
30 ms |
6396 KB |
Output is correct |
14 |
Correct |
27 ms |
6492 KB |
Output is correct |
15 |
Correct |
22 ms |
6232 KB |
Output is correct |
16 |
Correct |
29 ms |
6236 KB |
Output is correct |
17 |
Correct |
14 ms |
6400 KB |
Output is correct |
18 |
Correct |
19 ms |
6488 KB |
Output is correct |
19 |
Correct |
23 ms |
6232 KB |
Output is correct |
20 |
Correct |
38 ms |
6232 KB |
Output is correct |
21 |
Correct |
49 ms |
6236 KB |
Output is correct |
22 |
Correct |
58 ms |
6384 KB |
Output is correct |
23 |
Correct |
32 ms |
6396 KB |
Output is correct |
24 |
Correct |
89 ms |
6236 KB |
Output is correct |
25 |
Correct |
82 ms |
6380 KB |
Output is correct |
26 |
Correct |
69 ms |
6380 KB |
Output is correct |
27 |
Correct |
68 ms |
6376 KB |
Output is correct |
28 |
Correct |
91 ms |
6236 KB |
Output is correct |
29 |
Correct |
83 ms |
6236 KB |
Output is correct |
30 |
Correct |
69 ms |
6376 KB |
Output is correct |
31 |
Correct |
82 ms |
6236 KB |
Output is correct |
32 |
Correct |
92 ms |
6352 KB |
Output is correct |
33 |
Correct |
77 ms |
6356 KB |
Output is correct |
34 |
Correct |
73 ms |
6352 KB |
Output is correct |
35 |
Correct |
73 ms |
6492 KB |
Output is correct |
36 |
Correct |
89 ms |
6236 KB |
Output is correct |
37 |
Correct |
176 ms |
6636 KB |
Output is correct |
38 |
Correct |
198 ms |
6488 KB |
Output is correct |
39 |
Correct |
243 ms |
6376 KB |
Output is correct |
40 |
Correct |
227 ms |
6484 KB |
Output is correct |
41 |
Correct |
217 ms |
6376 KB |
Output is correct |
42 |
Correct |
207 ms |
6640 KB |
Output is correct |
43 |
Correct |
236 ms |
6872 KB |
Output is correct |
44 |
Correct |
263 ms |
6764 KB |
Output is correct |
45 |
Correct |
233 ms |
6768 KB |
Output is correct |
46 |
Correct |
194 ms |
6236 KB |
Output is correct |
47 |
Correct |
222 ms |
6484 KB |
Output is correct |
48 |
Correct |
244 ms |
6736 KB |
Output is correct |
49 |
Correct |
226 ms |
6484 KB |
Output is correct |
50 |
Correct |
210 ms |
6484 KB |
Output is correct |
51 |
Correct |
54 ms |
6384 KB |
Output is correct |
52 |
Correct |
308 ms |
6872 KB |
Output is correct |
53 |
Correct |
279 ms |
6740 KB |
Output is correct |
54 |
Correct |
394 ms |
6768 KB |
Output is correct |
55 |
Correct |
405 ms |
7128 KB |
Output is correct |
56 |
Correct |
358 ms |
6764 KB |
Output is correct |
57 |
Correct |
428 ms |
7020 KB |
Output is correct |
58 |
Correct |
384 ms |
6764 KB |
Output is correct |
59 |
Correct |
424 ms |
7024 KB |
Output is correct |
60 |
Correct |
77 ms |
6236 KB |
Output is correct |
61 |
Correct |
386 ms |
7024 KB |
Output is correct |
62 |
Correct |
387 ms |
7124 KB |
Output is correct |
63 |
Correct |
374 ms |
7020 KB |
Output is correct |
64 |
Correct |
374 ms |
7020 KB |
Output is correct |
65 |
Correct |
261 ms |
6380 KB |
Output is correct |
66 |
Correct |
255 ms |
6392 KB |
Output is correct |
67 |
Correct |
407 ms |
6976 KB |
Output is correct |
68 |
Correct |
107 ms |
6356 KB |
Output is correct |
69 |
Correct |
690 ms |
7804 KB |
Output is correct |
70 |
Correct |
605 ms |
7276 KB |
Output is correct |
71 |
Correct |
660 ms |
7276 KB |
Output is correct |
72 |
Correct |
568 ms |
6372 KB |
Output is correct |
73 |
Correct |
544 ms |
6380 KB |
Output is correct |
74 |
Correct |
696 ms |
8056 KB |
Output is correct |
75 |
Correct |
645 ms |
7632 KB |
Output is correct |
76 |
Correct |
742 ms |
7784 KB |
Output is correct |
77 |
Correct |
772 ms |
8056 KB |
Output is correct |