/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")
#include<bits/stdc++.h>
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define nl "\n"
using namespace std;
using pii = pair<int, int>;
const int N = (int)5e2 + 7; // make sure this is right
const int M = N * N;
const int inf = (int)1e9;
const ll INF = (ll)3e18 + 7;
const ll MOD = (ll)1e18 + 7; // make sure this is right
pii dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int n, a[N];
ll dp[M], cnt[M];
ll sum(ll x, ll y) {
x += y;
if(x >= MOD) x -= MOD;
return x;
}
ll sub(ll x, ll y) {
x -= y;
if(x < 0) x += MOD;
return x;
}
void add(int x) {
for(int i = M - 1; i >= x; --i) {
dp[i] = sum(dp[i], dp[i - x]);
}
}
void del(int x) {
for(int i = x; i < M; ++i) {
dp[i] = sub(dp[i], dp[i - x]);
}
}
void solve() {
cin >> n;
dp[0] = 1;
int sum = 0;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
add(a[i]);
sum += a[i];
}
if((sum & 1) || !dp[sum / 2]) {
cout << "0\n";
return;
}
for(int i = 1; i <= n; ++i) {
del(a[i]);
for(int x = 1; x < M; ++x) {
if(dp[x] > 0 && 2 * x > sum - a[i]) {
int need = 2 * x - sum + a[i];
cnt[need]++;
}
}
add(a[i]);
}
vector<int> ans;
for(int x = 1; x < M; ++x) if(cnt[x] == n) ans.pb(x);
cout << sz(ans) << nl;
for(auto x : ans) cout << x << ' ';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case #" << i << ": ";
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
8 ms |
2340 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
5 ms |
2260 KB |
Output is correct |
5 |
Correct |
13 ms |
2260 KB |
Output is correct |
6 |
Correct |
10 ms |
2260 KB |
Output is correct |
7 |
Correct |
10 ms |
2260 KB |
Output is correct |
8 |
Correct |
12 ms |
2348 KB |
Output is correct |
9 |
Correct |
11 ms |
2348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
8 ms |
2340 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
5 ms |
2260 KB |
Output is correct |
5 |
Correct |
13 ms |
2260 KB |
Output is correct |
6 |
Correct |
10 ms |
2260 KB |
Output is correct |
7 |
Correct |
10 ms |
2260 KB |
Output is correct |
8 |
Correct |
12 ms |
2348 KB |
Output is correct |
9 |
Correct |
11 ms |
2348 KB |
Output is correct |
10 |
Correct |
29 ms |
2260 KB |
Output is correct |
11 |
Correct |
30 ms |
2260 KB |
Output is correct |
12 |
Correct |
29 ms |
2260 KB |
Output is correct |
13 |
Correct |
27 ms |
2260 KB |
Output is correct |
14 |
Correct |
27 ms |
2260 KB |
Output is correct |
15 |
Correct |
29 ms |
2260 KB |
Output is correct |
16 |
Correct |
31 ms |
2260 KB |
Output is correct |
17 |
Correct |
20 ms |
2428 KB |
Output is correct |
18 |
Correct |
23 ms |
2260 KB |
Output is correct |
19 |
Correct |
25 ms |
2340 KB |
Output is correct |
20 |
Correct |
28 ms |
2336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
8 ms |
2340 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
5 ms |
2260 KB |
Output is correct |
5 |
Correct |
13 ms |
2260 KB |
Output is correct |
6 |
Correct |
10 ms |
2260 KB |
Output is correct |
7 |
Correct |
10 ms |
2260 KB |
Output is correct |
8 |
Correct |
12 ms |
2348 KB |
Output is correct |
9 |
Correct |
11 ms |
2348 KB |
Output is correct |
10 |
Correct |
29 ms |
2260 KB |
Output is correct |
11 |
Correct |
30 ms |
2260 KB |
Output is correct |
12 |
Correct |
29 ms |
2260 KB |
Output is correct |
13 |
Correct |
27 ms |
2260 KB |
Output is correct |
14 |
Correct |
27 ms |
2260 KB |
Output is correct |
15 |
Correct |
29 ms |
2260 KB |
Output is correct |
16 |
Correct |
31 ms |
2260 KB |
Output is correct |
17 |
Correct |
20 ms |
2428 KB |
Output is correct |
18 |
Correct |
23 ms |
2260 KB |
Output is correct |
19 |
Correct |
25 ms |
2340 KB |
Output is correct |
20 |
Correct |
28 ms |
2336 KB |
Output is correct |
21 |
Correct |
74 ms |
2344 KB |
Output is correct |
22 |
Correct |
88 ms |
2464 KB |
Output is correct |
23 |
Correct |
53 ms |
2340 KB |
Output is correct |
24 |
Correct |
91 ms |
2380 KB |
Output is correct |
25 |
Correct |
89 ms |
2340 KB |
Output is correct |
26 |
Correct |
105 ms |
2336 KB |
Output is correct |
27 |
Correct |
110 ms |
2384 KB |
Output is correct |
28 |
Correct |
103 ms |
2344 KB |
Output is correct |
29 |
Correct |
91 ms |
2396 KB |
Output is correct |
30 |
Correct |
125 ms |
2340 KB |
Output is correct |
31 |
Correct |
105 ms |
2380 KB |
Output is correct |
32 |
Correct |
111 ms |
2332 KB |
Output is correct |
33 |
Correct |
91 ms |
2380 KB |
Output is correct |
34 |
Correct |
100 ms |
2340 KB |
Output is correct |
35 |
Correct |
105 ms |
2404 KB |
Output is correct |
36 |
Correct |
106 ms |
2380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
8 ms |
2340 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
5 ms |
2260 KB |
Output is correct |
5 |
Correct |
13 ms |
2260 KB |
Output is correct |
6 |
Correct |
10 ms |
2260 KB |
Output is correct |
7 |
Correct |
10 ms |
2260 KB |
Output is correct |
8 |
Correct |
12 ms |
2348 KB |
Output is correct |
9 |
Correct |
11 ms |
2348 KB |
Output is correct |
10 |
Correct |
29 ms |
2260 KB |
Output is correct |
11 |
Correct |
30 ms |
2260 KB |
Output is correct |
12 |
Correct |
29 ms |
2260 KB |
Output is correct |
13 |
Correct |
27 ms |
2260 KB |
Output is correct |
14 |
Correct |
27 ms |
2260 KB |
Output is correct |
15 |
Correct |
29 ms |
2260 KB |
Output is correct |
16 |
Correct |
31 ms |
2260 KB |
Output is correct |
17 |
Correct |
20 ms |
2428 KB |
Output is correct |
18 |
Correct |
23 ms |
2260 KB |
Output is correct |
19 |
Correct |
25 ms |
2340 KB |
Output is correct |
20 |
Correct |
28 ms |
2336 KB |
Output is correct |
21 |
Correct |
74 ms |
2344 KB |
Output is correct |
22 |
Correct |
88 ms |
2464 KB |
Output is correct |
23 |
Correct |
53 ms |
2340 KB |
Output is correct |
24 |
Correct |
91 ms |
2380 KB |
Output is correct |
25 |
Correct |
89 ms |
2340 KB |
Output is correct |
26 |
Correct |
105 ms |
2336 KB |
Output is correct |
27 |
Correct |
110 ms |
2384 KB |
Output is correct |
28 |
Correct |
103 ms |
2344 KB |
Output is correct |
29 |
Correct |
91 ms |
2396 KB |
Output is correct |
30 |
Correct |
125 ms |
2340 KB |
Output is correct |
31 |
Correct |
105 ms |
2380 KB |
Output is correct |
32 |
Correct |
111 ms |
2332 KB |
Output is correct |
33 |
Correct |
91 ms |
2380 KB |
Output is correct |
34 |
Correct |
100 ms |
2340 KB |
Output is correct |
35 |
Correct |
105 ms |
2404 KB |
Output is correct |
36 |
Correct |
106 ms |
2380 KB |
Output is correct |
37 |
Correct |
204 ms |
2628 KB |
Output is correct |
38 |
Correct |
228 ms |
2540 KB |
Output is correct |
39 |
Correct |
220 ms |
2800 KB |
Output is correct |
40 |
Correct |
275 ms |
2764 KB |
Output is correct |
41 |
Correct |
269 ms |
2832 KB |
Output is correct |
42 |
Correct |
305 ms |
2720 KB |
Output is correct |
43 |
Correct |
262 ms |
3096 KB |
Output is correct |
44 |
Correct |
283 ms |
3148 KB |
Output is correct |
45 |
Correct |
274 ms |
3148 KB |
Output is correct |
46 |
Correct |
270 ms |
2564 KB |
Output is correct |
47 |
Correct |
288 ms |
2700 KB |
Output is correct |
48 |
Correct |
297 ms |
3052 KB |
Output is correct |
49 |
Correct |
243 ms |
2800 KB |
Output is correct |
50 |
Correct |
274 ms |
2724 KB |
Output is correct |
51 |
Correct |
71 ms |
2324 KB |
Output is correct |
52 |
Correct |
303 ms |
3216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
8 ms |
2340 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
5 ms |
2260 KB |
Output is correct |
5 |
Correct |
13 ms |
2260 KB |
Output is correct |
6 |
Correct |
10 ms |
2260 KB |
Output is correct |
7 |
Correct |
10 ms |
2260 KB |
Output is correct |
8 |
Correct |
12 ms |
2348 KB |
Output is correct |
9 |
Correct |
11 ms |
2348 KB |
Output is correct |
10 |
Correct |
29 ms |
2260 KB |
Output is correct |
11 |
Correct |
30 ms |
2260 KB |
Output is correct |
12 |
Correct |
29 ms |
2260 KB |
Output is correct |
13 |
Correct |
27 ms |
2260 KB |
Output is correct |
14 |
Correct |
27 ms |
2260 KB |
Output is correct |
15 |
Correct |
29 ms |
2260 KB |
Output is correct |
16 |
Correct |
31 ms |
2260 KB |
Output is correct |
17 |
Correct |
20 ms |
2428 KB |
Output is correct |
18 |
Correct |
23 ms |
2260 KB |
Output is correct |
19 |
Correct |
25 ms |
2340 KB |
Output is correct |
20 |
Correct |
28 ms |
2336 KB |
Output is correct |
21 |
Correct |
74 ms |
2344 KB |
Output is correct |
22 |
Correct |
88 ms |
2464 KB |
Output is correct |
23 |
Correct |
53 ms |
2340 KB |
Output is correct |
24 |
Correct |
91 ms |
2380 KB |
Output is correct |
25 |
Correct |
89 ms |
2340 KB |
Output is correct |
26 |
Correct |
105 ms |
2336 KB |
Output is correct |
27 |
Correct |
110 ms |
2384 KB |
Output is correct |
28 |
Correct |
103 ms |
2344 KB |
Output is correct |
29 |
Correct |
91 ms |
2396 KB |
Output is correct |
30 |
Correct |
125 ms |
2340 KB |
Output is correct |
31 |
Correct |
105 ms |
2380 KB |
Output is correct |
32 |
Correct |
111 ms |
2332 KB |
Output is correct |
33 |
Correct |
91 ms |
2380 KB |
Output is correct |
34 |
Correct |
100 ms |
2340 KB |
Output is correct |
35 |
Correct |
105 ms |
2404 KB |
Output is correct |
36 |
Correct |
106 ms |
2380 KB |
Output is correct |
37 |
Correct |
204 ms |
2628 KB |
Output is correct |
38 |
Correct |
228 ms |
2540 KB |
Output is correct |
39 |
Correct |
220 ms |
2800 KB |
Output is correct |
40 |
Correct |
275 ms |
2764 KB |
Output is correct |
41 |
Correct |
269 ms |
2832 KB |
Output is correct |
42 |
Correct |
305 ms |
2720 KB |
Output is correct |
43 |
Correct |
262 ms |
3096 KB |
Output is correct |
44 |
Correct |
283 ms |
3148 KB |
Output is correct |
45 |
Correct |
274 ms |
3148 KB |
Output is correct |
46 |
Correct |
270 ms |
2564 KB |
Output is correct |
47 |
Correct |
288 ms |
2700 KB |
Output is correct |
48 |
Correct |
297 ms |
3052 KB |
Output is correct |
49 |
Correct |
243 ms |
2800 KB |
Output is correct |
50 |
Correct |
274 ms |
2724 KB |
Output is correct |
51 |
Correct |
71 ms |
2324 KB |
Output is correct |
52 |
Correct |
303 ms |
3216 KB |
Output is correct |
53 |
Correct |
335 ms |
2960 KB |
Output is correct |
54 |
Correct |
424 ms |
3128 KB |
Output is correct |
55 |
Correct |
462 ms |
3732 KB |
Output is correct |
56 |
Correct |
385 ms |
3144 KB |
Output is correct |
57 |
Correct |
504 ms |
3876 KB |
Output is correct |
58 |
Correct |
423 ms |
3184 KB |
Output is correct |
59 |
Correct |
419 ms |
3308 KB |
Output is correct |
60 |
Correct |
96 ms |
2324 KB |
Output is correct |
61 |
Correct |
475 ms |
3528 KB |
Output is correct |
62 |
Correct |
399 ms |
3620 KB |
Output is correct |
63 |
Correct |
419 ms |
3648 KB |
Output is correct |
64 |
Correct |
460 ms |
3632 KB |
Output is correct |
65 |
Correct |
301 ms |
2636 KB |
Output is correct |
66 |
Correct |
294 ms |
2740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
8 ms |
2340 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
5 ms |
2260 KB |
Output is correct |
5 |
Correct |
13 ms |
2260 KB |
Output is correct |
6 |
Correct |
10 ms |
2260 KB |
Output is correct |
7 |
Correct |
10 ms |
2260 KB |
Output is correct |
8 |
Correct |
12 ms |
2348 KB |
Output is correct |
9 |
Correct |
11 ms |
2348 KB |
Output is correct |
10 |
Correct |
29 ms |
2260 KB |
Output is correct |
11 |
Correct |
30 ms |
2260 KB |
Output is correct |
12 |
Correct |
29 ms |
2260 KB |
Output is correct |
13 |
Correct |
27 ms |
2260 KB |
Output is correct |
14 |
Correct |
27 ms |
2260 KB |
Output is correct |
15 |
Correct |
29 ms |
2260 KB |
Output is correct |
16 |
Correct |
31 ms |
2260 KB |
Output is correct |
17 |
Correct |
20 ms |
2428 KB |
Output is correct |
18 |
Correct |
23 ms |
2260 KB |
Output is correct |
19 |
Correct |
25 ms |
2340 KB |
Output is correct |
20 |
Correct |
28 ms |
2336 KB |
Output is correct |
21 |
Correct |
74 ms |
2344 KB |
Output is correct |
22 |
Correct |
88 ms |
2464 KB |
Output is correct |
23 |
Correct |
53 ms |
2340 KB |
Output is correct |
24 |
Correct |
91 ms |
2380 KB |
Output is correct |
25 |
Correct |
89 ms |
2340 KB |
Output is correct |
26 |
Correct |
105 ms |
2336 KB |
Output is correct |
27 |
Correct |
110 ms |
2384 KB |
Output is correct |
28 |
Correct |
103 ms |
2344 KB |
Output is correct |
29 |
Correct |
91 ms |
2396 KB |
Output is correct |
30 |
Correct |
125 ms |
2340 KB |
Output is correct |
31 |
Correct |
105 ms |
2380 KB |
Output is correct |
32 |
Correct |
111 ms |
2332 KB |
Output is correct |
33 |
Correct |
91 ms |
2380 KB |
Output is correct |
34 |
Correct |
100 ms |
2340 KB |
Output is correct |
35 |
Correct |
105 ms |
2404 KB |
Output is correct |
36 |
Correct |
106 ms |
2380 KB |
Output is correct |
37 |
Correct |
204 ms |
2628 KB |
Output is correct |
38 |
Correct |
228 ms |
2540 KB |
Output is correct |
39 |
Correct |
220 ms |
2800 KB |
Output is correct |
40 |
Correct |
275 ms |
2764 KB |
Output is correct |
41 |
Correct |
269 ms |
2832 KB |
Output is correct |
42 |
Correct |
305 ms |
2720 KB |
Output is correct |
43 |
Correct |
262 ms |
3096 KB |
Output is correct |
44 |
Correct |
283 ms |
3148 KB |
Output is correct |
45 |
Correct |
274 ms |
3148 KB |
Output is correct |
46 |
Correct |
270 ms |
2564 KB |
Output is correct |
47 |
Correct |
288 ms |
2700 KB |
Output is correct |
48 |
Correct |
297 ms |
3052 KB |
Output is correct |
49 |
Correct |
243 ms |
2800 KB |
Output is correct |
50 |
Correct |
274 ms |
2724 KB |
Output is correct |
51 |
Correct |
71 ms |
2324 KB |
Output is correct |
52 |
Correct |
303 ms |
3216 KB |
Output is correct |
53 |
Correct |
335 ms |
2960 KB |
Output is correct |
54 |
Correct |
424 ms |
3128 KB |
Output is correct |
55 |
Correct |
462 ms |
3732 KB |
Output is correct |
56 |
Correct |
385 ms |
3144 KB |
Output is correct |
57 |
Correct |
504 ms |
3876 KB |
Output is correct |
58 |
Correct |
423 ms |
3184 KB |
Output is correct |
59 |
Correct |
419 ms |
3308 KB |
Output is correct |
60 |
Correct |
96 ms |
2324 KB |
Output is correct |
61 |
Correct |
475 ms |
3528 KB |
Output is correct |
62 |
Correct |
399 ms |
3620 KB |
Output is correct |
63 |
Correct |
419 ms |
3648 KB |
Output is correct |
64 |
Correct |
460 ms |
3632 KB |
Output is correct |
65 |
Correct |
301 ms |
2636 KB |
Output is correct |
66 |
Correct |
294 ms |
2740 KB |
Output is correct |
67 |
Correct |
503 ms |
3476 KB |
Output is correct |
68 |
Correct |
133 ms |
2320 KB |
Output is correct |
69 |
Correct |
894 ms |
5124 KB |
Output is correct |
70 |
Correct |
702 ms |
4092 KB |
Output is correct |
71 |
Correct |
733 ms |
4172 KB |
Output is correct |
72 |
Correct |
699 ms |
3380 KB |
Output is correct |
73 |
Correct |
731 ms |
3356 KB |
Output is correct |
74 |
Correct |
946 ms |
5216 KB |
Output is correct |
75 |
Correct |
811 ms |
4640 KB |
Output is correct |
76 |
Correct |
938 ms |
5356 KB |
Output is correct |
77 |
Correct |
931 ms |
5460 KB |
Output is correct |