/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef pair<pii, int> piii;
typedef pair<ll, pll> lpll;
typedef pair<pll, ll> plll;
typedef pair<pii, pii> piipii;
typedef pair<pll, pll> pllpll;
typedef long double ld;
#define SQ 350
#define endl '\n'
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define PQ priority_queue
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define ios ios_base::sync_with_stdio(false), cin.tie(0)
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
const int N = 2e5+25, lg=18;
int Mod = 3e8+13;
//ll Mod = 998244353;
ll max(ll a, ll b) {return (a>b ? a : b);}
ll min(ll a, ll b) {return (a<b ? a : b);}
ll abso(ll a) {return (a<0?-a:a);}
inline int MOD(int a, int mod=Mod) {
a += mod;
while(a>=mod) a-=mod;
return a;
}
inline ll poww(ll a, ll b) {
ll ans = 1;
a=MOD(a);
while (b) {
if (b & 1) ans = MOD(ans*a);
b >>= 1;
a = MOD(a*a);
}
return ans;
}
int n, A[505], dp[505*505], tmp[505*505], num[N], sum, z;
int main () {
//ios;
cin>>n;
for(int i=1; i<=n; i++) cin>>A[i], sum+=A[i];
for(int i=1; i<n; i++) if(MOD(A[i]%2, 2)!=MOD(A[i+1]%2, 2)) z = 1;
if(z || MOD(sum%2, 2)==1) kill(0);
dp[0] = 1;
for(int i=1; i<=n; i++) {
for(int j=sum; j>=A[i]; j--) {
dp[j] = MOD(dp[j] + dp[j-A[i]]);
}
}
for(int i=1; i<=n; i++) {
for(int j=A[i]; j<=sum; j++) {
tmp[j] = dp[j];
dp[j] = MOD(dp[j] - dp[j-A[i]]);
}
for(int f=MOD(A[1]%2, 2); f<=sum; f+=2) {
if(dp[(f+sum-A[i])/2]>0) num[f]++;
}
for(int j=sum; j>=A[i]; j--) dp[j] = tmp[j];
}
vector<ll> ans;
for(int i=0; i<=sum; i++) {
if(num[i]==n && dp[sum/2]>0) ans.pb(i);
}
cout<<size(ans)<<endl;
for(auto i : ans) {cout<<i<<' ';}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
6 ms |
428 KB |
Output is correct |
26 |
Correct |
6 ms |
480 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
6 ms |
468 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
4 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
6 ms |
428 KB |
Output is correct |
26 |
Correct |
6 ms |
480 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
6 ms |
468 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
4 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
32 ms |
724 KB |
Output is correct |
38 |
Correct |
32 ms |
760 KB |
Output is correct |
39 |
Correct |
37 ms |
1048 KB |
Output is correct |
40 |
Correct |
74 ms |
944 KB |
Output is correct |
41 |
Correct |
46 ms |
1156 KB |
Output is correct |
42 |
Correct |
63 ms |
916 KB |
Output is correct |
43 |
Correct |
113 ms |
1400 KB |
Output is correct |
44 |
Correct |
112 ms |
1352 KB |
Output is correct |
45 |
Correct |
116 ms |
1408 KB |
Output is correct |
46 |
Correct |
45 ms |
568 KB |
Output is correct |
47 |
Correct |
70 ms |
944 KB |
Output is correct |
48 |
Correct |
103 ms |
1304 KB |
Output is correct |
49 |
Correct |
76 ms |
1152 KB |
Output is correct |
50 |
Correct |
70 ms |
936 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
144 ms |
1548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
6 ms |
428 KB |
Output is correct |
26 |
Correct |
6 ms |
480 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
6 ms |
468 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
4 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
32 ms |
724 KB |
Output is correct |
38 |
Correct |
32 ms |
760 KB |
Output is correct |
39 |
Correct |
37 ms |
1048 KB |
Output is correct |
40 |
Correct |
74 ms |
944 KB |
Output is correct |
41 |
Correct |
46 ms |
1156 KB |
Output is correct |
42 |
Correct |
63 ms |
916 KB |
Output is correct |
43 |
Correct |
113 ms |
1400 KB |
Output is correct |
44 |
Correct |
112 ms |
1352 KB |
Output is correct |
45 |
Correct |
116 ms |
1408 KB |
Output is correct |
46 |
Correct |
45 ms |
568 KB |
Output is correct |
47 |
Correct |
70 ms |
944 KB |
Output is correct |
48 |
Correct |
103 ms |
1304 KB |
Output is correct |
49 |
Correct |
76 ms |
1152 KB |
Output is correct |
50 |
Correct |
70 ms |
936 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
144 ms |
1548 KB |
Output is correct |
53 |
Correct |
114 ms |
1252 KB |
Output is correct |
54 |
Correct |
163 ms |
1404 KB |
Output is correct |
55 |
Correct |
306 ms |
2364 KB |
Output is correct |
56 |
Correct |
142 ms |
1464 KB |
Output is correct |
57 |
Correct |
328 ms |
2412 KB |
Output is correct |
58 |
Correct |
181 ms |
1480 KB |
Output is correct |
59 |
Correct |
222 ms |
1740 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
255 ms |
1932 KB |
Output is correct |
62 |
Correct |
265 ms |
2080 KB |
Output is correct |
63 |
Correct |
274 ms |
2272 KB |
Output is correct |
64 |
Correct |
260 ms |
2256 KB |
Output is correct |
65 |
Correct |
40 ms |
852 KB |
Output is correct |
66 |
Correct |
58 ms |
1064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
6 ms |
428 KB |
Output is correct |
26 |
Correct |
6 ms |
480 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
6 ms |
468 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
4 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
32 ms |
724 KB |
Output is correct |
38 |
Correct |
32 ms |
760 KB |
Output is correct |
39 |
Correct |
37 ms |
1048 KB |
Output is correct |
40 |
Correct |
74 ms |
944 KB |
Output is correct |
41 |
Correct |
46 ms |
1156 KB |
Output is correct |
42 |
Correct |
63 ms |
916 KB |
Output is correct |
43 |
Correct |
113 ms |
1400 KB |
Output is correct |
44 |
Correct |
112 ms |
1352 KB |
Output is correct |
45 |
Correct |
116 ms |
1408 KB |
Output is correct |
46 |
Correct |
45 ms |
568 KB |
Output is correct |
47 |
Correct |
70 ms |
944 KB |
Output is correct |
48 |
Correct |
103 ms |
1304 KB |
Output is correct |
49 |
Correct |
76 ms |
1152 KB |
Output is correct |
50 |
Correct |
70 ms |
936 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
144 ms |
1548 KB |
Output is correct |
53 |
Correct |
114 ms |
1252 KB |
Output is correct |
54 |
Correct |
163 ms |
1404 KB |
Output is correct |
55 |
Correct |
306 ms |
2364 KB |
Output is correct |
56 |
Correct |
142 ms |
1464 KB |
Output is correct |
57 |
Correct |
328 ms |
2412 KB |
Output is correct |
58 |
Correct |
181 ms |
1480 KB |
Output is correct |
59 |
Correct |
222 ms |
1740 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
255 ms |
1932 KB |
Output is correct |
62 |
Correct |
265 ms |
2080 KB |
Output is correct |
63 |
Correct |
274 ms |
2272 KB |
Output is correct |
64 |
Correct |
260 ms |
2256 KB |
Output is correct |
65 |
Correct |
40 ms |
852 KB |
Output is correct |
66 |
Correct |
58 ms |
1064 KB |
Output is correct |
67 |
Correct |
254 ms |
1896 KB |
Output is correct |
68 |
Correct |
343 ms |
1692 KB |
Output is correct |
69 |
Incorrect |
877 ms |
4328 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |