/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 3e5+23, lg = 18;
int Mod = 1e9+7; //998244353;
inline int MOD(int a, int mod=Mod) {
while(a>=mod) {a-=mod;}
(a<0)&&(a+=mod);
return a;
}
int n, sum, a[505], res[505*505], dp[505*505];
void add(int i) {
for(int x=500*500; x>=a[i]; x--) {
dp[x] = (dp[x] + dp[x-a[i]]);
}
}
void del(int i) {
for(int x=a[i]; x<=500*500; x++) {
dp[x] = (dp[x] - dp[x-a[i]]);
}
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++) {
cin>>a[i]; sum+=a[i];
}
dp[0] = 1;
for(int i=1; i<=n; i++) {
add(i);
}
if(dp[sum/2] == 0 || sum%2==1) kill(0);
for(int i=1; i<=n; i++) {
del(i);
int x = (sum-a[i])%2;
for(int j=(x==0?2:1); j<=500*500; j+=2) {
res[j] |= (dp[(sum-a[i]+j)/2] == 0);
}
for(int j=(x==0?1:2); j<=500*500; j+=2) {
res[j] |= 1;
}
add(i);
}
vector<int> ans;
for(int i=1; i<=500*500; i++) {
if(res[i] == 0) ans.pb(i);
}
cout<<size(ans)<<endl;
for(auto it : ans) {
cout<<it<<' ';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
4 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2396 KB |
Output is correct |
6 |
Correct |
5 ms |
2204 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2212 KB |
Output is correct |
9 |
Correct |
4 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
4 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2396 KB |
Output is correct |
6 |
Correct |
5 ms |
2204 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2212 KB |
Output is correct |
9 |
Correct |
4 ms |
2396 KB |
Output is correct |
10 |
Correct |
13 ms |
2420 KB |
Output is correct |
11 |
Correct |
18 ms |
2376 KB |
Output is correct |
12 |
Correct |
17 ms |
2420 KB |
Output is correct |
13 |
Correct |
14 ms |
2420 KB |
Output is correct |
14 |
Correct |
15 ms |
2416 KB |
Output is correct |
15 |
Correct |
16 ms |
2396 KB |
Output is correct |
16 |
Correct |
18 ms |
2396 KB |
Output is correct |
17 |
Correct |
11 ms |
2396 KB |
Output is correct |
18 |
Correct |
17 ms |
2420 KB |
Output is correct |
19 |
Correct |
15 ms |
2396 KB |
Output is correct |
20 |
Correct |
12 ms |
2332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
4 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2396 KB |
Output is correct |
6 |
Correct |
5 ms |
2204 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2212 KB |
Output is correct |
9 |
Correct |
4 ms |
2396 KB |
Output is correct |
10 |
Correct |
13 ms |
2420 KB |
Output is correct |
11 |
Correct |
18 ms |
2376 KB |
Output is correct |
12 |
Correct |
17 ms |
2420 KB |
Output is correct |
13 |
Correct |
14 ms |
2420 KB |
Output is correct |
14 |
Correct |
15 ms |
2416 KB |
Output is correct |
15 |
Correct |
16 ms |
2396 KB |
Output is correct |
16 |
Correct |
18 ms |
2396 KB |
Output is correct |
17 |
Correct |
11 ms |
2396 KB |
Output is correct |
18 |
Correct |
17 ms |
2420 KB |
Output is correct |
19 |
Correct |
15 ms |
2396 KB |
Output is correct |
20 |
Correct |
12 ms |
2332 KB |
Output is correct |
21 |
Correct |
27 ms |
2420 KB |
Output is correct |
22 |
Correct |
27 ms |
2236 KB |
Output is correct |
23 |
Correct |
26 ms |
2416 KB |
Output is correct |
24 |
Correct |
33 ms |
2400 KB |
Output is correct |
25 |
Correct |
42 ms |
2404 KB |
Output is correct |
26 |
Correct |
33 ms |
2404 KB |
Output is correct |
27 |
Correct |
33 ms |
2420 KB |
Output is correct |
28 |
Correct |
36 ms |
2408 KB |
Output is correct |
29 |
Correct |
38 ms |
2420 KB |
Output is correct |
30 |
Correct |
34 ms |
2408 KB |
Output is correct |
31 |
Correct |
30 ms |
2412 KB |
Output is correct |
32 |
Correct |
40 ms |
2396 KB |
Output is correct |
33 |
Correct |
32 ms |
2396 KB |
Output is correct |
34 |
Correct |
36 ms |
2396 KB |
Output is correct |
35 |
Correct |
30 ms |
2392 KB |
Output is correct |
36 |
Correct |
36 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
4 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2396 KB |
Output is correct |
6 |
Correct |
5 ms |
2204 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2212 KB |
Output is correct |
9 |
Correct |
4 ms |
2396 KB |
Output is correct |
10 |
Correct |
13 ms |
2420 KB |
Output is correct |
11 |
Correct |
18 ms |
2376 KB |
Output is correct |
12 |
Correct |
17 ms |
2420 KB |
Output is correct |
13 |
Correct |
14 ms |
2420 KB |
Output is correct |
14 |
Correct |
15 ms |
2416 KB |
Output is correct |
15 |
Correct |
16 ms |
2396 KB |
Output is correct |
16 |
Correct |
18 ms |
2396 KB |
Output is correct |
17 |
Correct |
11 ms |
2396 KB |
Output is correct |
18 |
Correct |
17 ms |
2420 KB |
Output is correct |
19 |
Correct |
15 ms |
2396 KB |
Output is correct |
20 |
Correct |
12 ms |
2332 KB |
Output is correct |
21 |
Correct |
27 ms |
2420 KB |
Output is correct |
22 |
Correct |
27 ms |
2236 KB |
Output is correct |
23 |
Correct |
26 ms |
2416 KB |
Output is correct |
24 |
Correct |
33 ms |
2400 KB |
Output is correct |
25 |
Correct |
42 ms |
2404 KB |
Output is correct |
26 |
Correct |
33 ms |
2404 KB |
Output is correct |
27 |
Correct |
33 ms |
2420 KB |
Output is correct |
28 |
Correct |
36 ms |
2408 KB |
Output is correct |
29 |
Correct |
38 ms |
2420 KB |
Output is correct |
30 |
Correct |
34 ms |
2408 KB |
Output is correct |
31 |
Correct |
30 ms |
2412 KB |
Output is correct |
32 |
Correct |
40 ms |
2396 KB |
Output is correct |
33 |
Correct |
32 ms |
2396 KB |
Output is correct |
34 |
Correct |
36 ms |
2396 KB |
Output is correct |
35 |
Correct |
30 ms |
2392 KB |
Output is correct |
36 |
Correct |
36 ms |
2396 KB |
Output is correct |
37 |
Correct |
70 ms |
2396 KB |
Output is correct |
38 |
Correct |
60 ms |
2396 KB |
Output is correct |
39 |
Correct |
70 ms |
2396 KB |
Output is correct |
40 |
Correct |
88 ms |
2412 KB |
Output is correct |
41 |
Correct |
79 ms |
2392 KB |
Output is correct |
42 |
Correct |
79 ms |
2392 KB |
Output is correct |
43 |
Correct |
71 ms |
2640 KB |
Output is correct |
44 |
Correct |
72 ms |
2652 KB |
Output is correct |
45 |
Correct |
72 ms |
2640 KB |
Output is correct |
46 |
Correct |
80 ms |
2396 KB |
Output is correct |
47 |
Correct |
77 ms |
2400 KB |
Output is correct |
48 |
Correct |
72 ms |
2644 KB |
Output is correct |
49 |
Correct |
74 ms |
2396 KB |
Output is correct |
50 |
Correct |
78 ms |
2396 KB |
Output is correct |
51 |
Correct |
12 ms |
1372 KB |
Output is correct |
52 |
Correct |
80 ms |
2708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
4 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2396 KB |
Output is correct |
6 |
Correct |
5 ms |
2204 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2212 KB |
Output is correct |
9 |
Correct |
4 ms |
2396 KB |
Output is correct |
10 |
Correct |
13 ms |
2420 KB |
Output is correct |
11 |
Correct |
18 ms |
2376 KB |
Output is correct |
12 |
Correct |
17 ms |
2420 KB |
Output is correct |
13 |
Correct |
14 ms |
2420 KB |
Output is correct |
14 |
Correct |
15 ms |
2416 KB |
Output is correct |
15 |
Correct |
16 ms |
2396 KB |
Output is correct |
16 |
Correct |
18 ms |
2396 KB |
Output is correct |
17 |
Correct |
11 ms |
2396 KB |
Output is correct |
18 |
Correct |
17 ms |
2420 KB |
Output is correct |
19 |
Correct |
15 ms |
2396 KB |
Output is correct |
20 |
Correct |
12 ms |
2332 KB |
Output is correct |
21 |
Correct |
27 ms |
2420 KB |
Output is correct |
22 |
Correct |
27 ms |
2236 KB |
Output is correct |
23 |
Correct |
26 ms |
2416 KB |
Output is correct |
24 |
Correct |
33 ms |
2400 KB |
Output is correct |
25 |
Correct |
42 ms |
2404 KB |
Output is correct |
26 |
Correct |
33 ms |
2404 KB |
Output is correct |
27 |
Correct |
33 ms |
2420 KB |
Output is correct |
28 |
Correct |
36 ms |
2408 KB |
Output is correct |
29 |
Correct |
38 ms |
2420 KB |
Output is correct |
30 |
Correct |
34 ms |
2408 KB |
Output is correct |
31 |
Correct |
30 ms |
2412 KB |
Output is correct |
32 |
Correct |
40 ms |
2396 KB |
Output is correct |
33 |
Correct |
32 ms |
2396 KB |
Output is correct |
34 |
Correct |
36 ms |
2396 KB |
Output is correct |
35 |
Correct |
30 ms |
2392 KB |
Output is correct |
36 |
Correct |
36 ms |
2396 KB |
Output is correct |
37 |
Correct |
70 ms |
2396 KB |
Output is correct |
38 |
Correct |
60 ms |
2396 KB |
Output is correct |
39 |
Correct |
70 ms |
2396 KB |
Output is correct |
40 |
Correct |
88 ms |
2412 KB |
Output is correct |
41 |
Correct |
79 ms |
2392 KB |
Output is correct |
42 |
Correct |
79 ms |
2392 KB |
Output is correct |
43 |
Correct |
71 ms |
2640 KB |
Output is correct |
44 |
Correct |
72 ms |
2652 KB |
Output is correct |
45 |
Correct |
72 ms |
2640 KB |
Output is correct |
46 |
Correct |
80 ms |
2396 KB |
Output is correct |
47 |
Correct |
77 ms |
2400 KB |
Output is correct |
48 |
Correct |
72 ms |
2644 KB |
Output is correct |
49 |
Correct |
74 ms |
2396 KB |
Output is correct |
50 |
Correct |
78 ms |
2396 KB |
Output is correct |
51 |
Correct |
12 ms |
1372 KB |
Output is correct |
52 |
Correct |
80 ms |
2708 KB |
Output is correct |
53 |
Correct |
88 ms |
2652 KB |
Output is correct |
54 |
Correct |
103 ms |
2644 KB |
Output is correct |
55 |
Correct |
108 ms |
3036 KB |
Output is correct |
56 |
Correct |
91 ms |
2640 KB |
Output is correct |
57 |
Correct |
102 ms |
3052 KB |
Output is correct |
58 |
Correct |
109 ms |
2648 KB |
Output is correct |
59 |
Correct |
101 ms |
2776 KB |
Output is correct |
60 |
Correct |
15 ms |
1372 KB |
Output is correct |
61 |
Correct |
105 ms |
2776 KB |
Output is correct |
62 |
Correct |
93 ms |
2784 KB |
Output is correct |
63 |
Correct |
95 ms |
2796 KB |
Output is correct |
64 |
Correct |
92 ms |
2796 KB |
Output is correct |
65 |
Correct |
93 ms |
2656 KB |
Output is correct |
66 |
Correct |
97 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
4 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2396 KB |
Output is correct |
6 |
Correct |
5 ms |
2204 KB |
Output is correct |
7 |
Correct |
3 ms |
2396 KB |
Output is correct |
8 |
Correct |
5 ms |
2212 KB |
Output is correct |
9 |
Correct |
4 ms |
2396 KB |
Output is correct |
10 |
Correct |
13 ms |
2420 KB |
Output is correct |
11 |
Correct |
18 ms |
2376 KB |
Output is correct |
12 |
Correct |
17 ms |
2420 KB |
Output is correct |
13 |
Correct |
14 ms |
2420 KB |
Output is correct |
14 |
Correct |
15 ms |
2416 KB |
Output is correct |
15 |
Correct |
16 ms |
2396 KB |
Output is correct |
16 |
Correct |
18 ms |
2396 KB |
Output is correct |
17 |
Correct |
11 ms |
2396 KB |
Output is correct |
18 |
Correct |
17 ms |
2420 KB |
Output is correct |
19 |
Correct |
15 ms |
2396 KB |
Output is correct |
20 |
Correct |
12 ms |
2332 KB |
Output is correct |
21 |
Correct |
27 ms |
2420 KB |
Output is correct |
22 |
Correct |
27 ms |
2236 KB |
Output is correct |
23 |
Correct |
26 ms |
2416 KB |
Output is correct |
24 |
Correct |
33 ms |
2400 KB |
Output is correct |
25 |
Correct |
42 ms |
2404 KB |
Output is correct |
26 |
Correct |
33 ms |
2404 KB |
Output is correct |
27 |
Correct |
33 ms |
2420 KB |
Output is correct |
28 |
Correct |
36 ms |
2408 KB |
Output is correct |
29 |
Correct |
38 ms |
2420 KB |
Output is correct |
30 |
Correct |
34 ms |
2408 KB |
Output is correct |
31 |
Correct |
30 ms |
2412 KB |
Output is correct |
32 |
Correct |
40 ms |
2396 KB |
Output is correct |
33 |
Correct |
32 ms |
2396 KB |
Output is correct |
34 |
Correct |
36 ms |
2396 KB |
Output is correct |
35 |
Correct |
30 ms |
2392 KB |
Output is correct |
36 |
Correct |
36 ms |
2396 KB |
Output is correct |
37 |
Correct |
70 ms |
2396 KB |
Output is correct |
38 |
Correct |
60 ms |
2396 KB |
Output is correct |
39 |
Correct |
70 ms |
2396 KB |
Output is correct |
40 |
Correct |
88 ms |
2412 KB |
Output is correct |
41 |
Correct |
79 ms |
2392 KB |
Output is correct |
42 |
Correct |
79 ms |
2392 KB |
Output is correct |
43 |
Correct |
71 ms |
2640 KB |
Output is correct |
44 |
Correct |
72 ms |
2652 KB |
Output is correct |
45 |
Correct |
72 ms |
2640 KB |
Output is correct |
46 |
Correct |
80 ms |
2396 KB |
Output is correct |
47 |
Correct |
77 ms |
2400 KB |
Output is correct |
48 |
Correct |
72 ms |
2644 KB |
Output is correct |
49 |
Correct |
74 ms |
2396 KB |
Output is correct |
50 |
Correct |
78 ms |
2396 KB |
Output is correct |
51 |
Correct |
12 ms |
1372 KB |
Output is correct |
52 |
Correct |
80 ms |
2708 KB |
Output is correct |
53 |
Correct |
88 ms |
2652 KB |
Output is correct |
54 |
Correct |
103 ms |
2644 KB |
Output is correct |
55 |
Correct |
108 ms |
3036 KB |
Output is correct |
56 |
Correct |
91 ms |
2640 KB |
Output is correct |
57 |
Correct |
102 ms |
3052 KB |
Output is correct |
58 |
Correct |
109 ms |
2648 KB |
Output is correct |
59 |
Correct |
101 ms |
2776 KB |
Output is correct |
60 |
Correct |
15 ms |
1372 KB |
Output is correct |
61 |
Correct |
105 ms |
2776 KB |
Output is correct |
62 |
Correct |
93 ms |
2784 KB |
Output is correct |
63 |
Correct |
95 ms |
2796 KB |
Output is correct |
64 |
Correct |
92 ms |
2796 KB |
Output is correct |
65 |
Correct |
93 ms |
2656 KB |
Output is correct |
66 |
Correct |
97 ms |
2396 KB |
Output is correct |
67 |
Correct |
121 ms |
2772 KB |
Output is correct |
68 |
Correct |
21 ms |
1368 KB |
Output is correct |
69 |
Correct |
154 ms |
3540 KB |
Output is correct |
70 |
Correct |
151 ms |
3048 KB |
Output is correct |
71 |
Correct |
149 ms |
3300 KB |
Output is correct |
72 |
Correct |
148 ms |
2396 KB |
Output is correct |
73 |
Correct |
148 ms |
2388 KB |
Output is correct |
74 |
Correct |
149 ms |
3548 KB |
Output is correct |
75 |
Correct |
147 ms |
3312 KB |
Output is correct |
76 |
Correct |
149 ms |
3548 KB |
Output is correct |
77 |
Correct |
148 ms |
3612 KB |
Output is correct |