//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree <pair <int, int>, null_type, less <pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
#define ll long long
#define db double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"
//#define int long long
using namespace std;
void dout() {
cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
cerr << H << ' ';
dout(T...);
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
const int N = 503, K = 250001;
const pii MOD = {1e9 + 7, 1e9 + 9};
int n, a[N], ans[K];
pii dp[K];
void add(pii & x, pii y) {
x.fi += y.fi;
if (x.fi >= MOD.fi) {
x.fi -= MOD.fi;
}
x.se += y.se;
if (x.se >= MOD.se) {
x.se -= MOD.se;
}
}
void sub(pii & x, pii y) {
x.fi -= y.fi;
if (x.fi < 0) {
x.fi += MOD.fi;
}
x.se -= y.se;
if (x.se < 0) {
x.se += MOD.se;
}
}
bool exist(int x) {
return dp[x].fi > 0 || dp[x].se > 0;
}
void solve(int tc) {
// check for (int i = 0; i < n; j++)
cin >> n;
dp[0] = {1, 1};
int total = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
total += a[i];
for (int j = K - 1; j >= a[i]; j--) {
add(dp[j], dp[j - a[i]]);
}
}
if ((total & 1) || !exist(total >> 1)) {
cout << 0;
return;
}
fill(ans, ans + K, 1);
int least = 1e9;
for (int i = 1; i <= n; i++) {
for (int j = a[i]; j < K; j++) {
sub(dp[j], dp[j - a[i]]);
}
total -= a[i];
least = min(least, total);
for (int j = 0; j <= total; j++) {
if ((j & 1) != (total & 1) || (!exist(total + j >> 1) && !exist(total - j >> 1))) {
ans[j] = 0;
}
}
total += a[i];
for (int j = K - 1; j >= a[i]; j--) {
add(dp[j], dp[j - a[i]]);
}
}
int cnt = 0;
for (int i = 0; i <= least; i++) {
if (ans[i]) {
cnt++;
}
}
cout << cnt << endl;
for (int i = 0; i <= least; i++) {
if (ans[i]) {
cout << i << " ";
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tc = 1;
// cin >> tc;
for (int i = 0; i < tc; i++) {
solve(i);
// cleanup();
}
}
Compilation message
bootfall.cpp: In function 'void solve(int)':
bootfall.cpp:94:57: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if ((j & 1) != (total & 1) || (!exist(total + j >> 1) && !exist(total - j >> 1))) {
~~~~~~^~~
bootfall.cpp:94:83: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
if ((j & 1) != (total & 1) || (!exist(total + j >> 1) && !exist(total - j >> 1))) {
~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3320 KB |
Output is correct |
2 |
Correct |
14 ms |
3320 KB |
Output is correct |
3 |
Correct |
6 ms |
2296 KB |
Output is correct |
4 |
Correct |
11 ms |
3320 KB |
Output is correct |
5 |
Correct |
22 ms |
3320 KB |
Output is correct |
6 |
Correct |
16 ms |
3324 KB |
Output is correct |
7 |
Correct |
14 ms |
3320 KB |
Output is correct |
8 |
Correct |
22 ms |
3320 KB |
Output is correct |
9 |
Correct |
19 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3320 KB |
Output is correct |
2 |
Correct |
14 ms |
3320 KB |
Output is correct |
3 |
Correct |
6 ms |
2296 KB |
Output is correct |
4 |
Correct |
11 ms |
3320 KB |
Output is correct |
5 |
Correct |
22 ms |
3320 KB |
Output is correct |
6 |
Correct |
16 ms |
3324 KB |
Output is correct |
7 |
Correct |
14 ms |
3320 KB |
Output is correct |
8 |
Correct |
22 ms |
3320 KB |
Output is correct |
9 |
Correct |
19 ms |
3320 KB |
Output is correct |
10 |
Correct |
47 ms |
3324 KB |
Output is correct |
11 |
Correct |
49 ms |
3320 KB |
Output is correct |
12 |
Correct |
47 ms |
3296 KB |
Output is correct |
13 |
Correct |
42 ms |
3448 KB |
Output is correct |
14 |
Correct |
44 ms |
3276 KB |
Output is correct |
15 |
Correct |
45 ms |
3196 KB |
Output is correct |
16 |
Correct |
48 ms |
3320 KB |
Output is correct |
17 |
Correct |
30 ms |
3320 KB |
Output is correct |
18 |
Correct |
39 ms |
3216 KB |
Output is correct |
19 |
Correct |
42 ms |
3320 KB |
Output is correct |
20 |
Correct |
47 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3320 KB |
Output is correct |
2 |
Correct |
14 ms |
3320 KB |
Output is correct |
3 |
Correct |
6 ms |
2296 KB |
Output is correct |
4 |
Correct |
11 ms |
3320 KB |
Output is correct |
5 |
Correct |
22 ms |
3320 KB |
Output is correct |
6 |
Correct |
16 ms |
3324 KB |
Output is correct |
7 |
Correct |
14 ms |
3320 KB |
Output is correct |
8 |
Correct |
22 ms |
3320 KB |
Output is correct |
9 |
Correct |
19 ms |
3320 KB |
Output is correct |
10 |
Correct |
47 ms |
3324 KB |
Output is correct |
11 |
Correct |
49 ms |
3320 KB |
Output is correct |
12 |
Correct |
47 ms |
3296 KB |
Output is correct |
13 |
Correct |
42 ms |
3448 KB |
Output is correct |
14 |
Correct |
44 ms |
3276 KB |
Output is correct |
15 |
Correct |
45 ms |
3196 KB |
Output is correct |
16 |
Correct |
48 ms |
3320 KB |
Output is correct |
17 |
Correct |
30 ms |
3320 KB |
Output is correct |
18 |
Correct |
39 ms |
3216 KB |
Output is correct |
19 |
Correct |
42 ms |
3320 KB |
Output is correct |
20 |
Correct |
47 ms |
3320 KB |
Output is correct |
21 |
Correct |
96 ms |
3360 KB |
Output is correct |
22 |
Correct |
110 ms |
3280 KB |
Output is correct |
23 |
Correct |
75 ms |
3356 KB |
Output is correct |
24 |
Correct |
137 ms |
3320 KB |
Output is correct |
25 |
Correct |
136 ms |
3320 KB |
Output is correct |
26 |
Correct |
146 ms |
3316 KB |
Output is correct |
27 |
Correct |
145 ms |
3320 KB |
Output is correct |
28 |
Correct |
145 ms |
3324 KB |
Output is correct |
29 |
Correct |
145 ms |
3320 KB |
Output is correct |
30 |
Correct |
143 ms |
3320 KB |
Output is correct |
31 |
Correct |
144 ms |
3396 KB |
Output is correct |
32 |
Correct |
144 ms |
3320 KB |
Output is correct |
33 |
Correct |
145 ms |
3360 KB |
Output is correct |
34 |
Correct |
145 ms |
3320 KB |
Output is correct |
35 |
Correct |
145 ms |
3320 KB |
Output is correct |
36 |
Correct |
145 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3320 KB |
Output is correct |
2 |
Correct |
14 ms |
3320 KB |
Output is correct |
3 |
Correct |
6 ms |
2296 KB |
Output is correct |
4 |
Correct |
11 ms |
3320 KB |
Output is correct |
5 |
Correct |
22 ms |
3320 KB |
Output is correct |
6 |
Correct |
16 ms |
3324 KB |
Output is correct |
7 |
Correct |
14 ms |
3320 KB |
Output is correct |
8 |
Correct |
22 ms |
3320 KB |
Output is correct |
9 |
Correct |
19 ms |
3320 KB |
Output is correct |
10 |
Correct |
47 ms |
3324 KB |
Output is correct |
11 |
Correct |
49 ms |
3320 KB |
Output is correct |
12 |
Correct |
47 ms |
3296 KB |
Output is correct |
13 |
Correct |
42 ms |
3448 KB |
Output is correct |
14 |
Correct |
44 ms |
3276 KB |
Output is correct |
15 |
Correct |
45 ms |
3196 KB |
Output is correct |
16 |
Correct |
48 ms |
3320 KB |
Output is correct |
17 |
Correct |
30 ms |
3320 KB |
Output is correct |
18 |
Correct |
39 ms |
3216 KB |
Output is correct |
19 |
Correct |
42 ms |
3320 KB |
Output is correct |
20 |
Correct |
47 ms |
3320 KB |
Output is correct |
21 |
Correct |
96 ms |
3360 KB |
Output is correct |
22 |
Correct |
110 ms |
3280 KB |
Output is correct |
23 |
Correct |
75 ms |
3356 KB |
Output is correct |
24 |
Correct |
137 ms |
3320 KB |
Output is correct |
25 |
Correct |
136 ms |
3320 KB |
Output is correct |
26 |
Correct |
146 ms |
3316 KB |
Output is correct |
27 |
Correct |
145 ms |
3320 KB |
Output is correct |
28 |
Correct |
145 ms |
3324 KB |
Output is correct |
29 |
Correct |
145 ms |
3320 KB |
Output is correct |
30 |
Correct |
143 ms |
3320 KB |
Output is correct |
31 |
Correct |
144 ms |
3396 KB |
Output is correct |
32 |
Correct |
144 ms |
3320 KB |
Output is correct |
33 |
Correct |
145 ms |
3360 KB |
Output is correct |
34 |
Correct |
145 ms |
3320 KB |
Output is correct |
35 |
Correct |
145 ms |
3320 KB |
Output is correct |
36 |
Correct |
145 ms |
3320 KB |
Output is correct |
37 |
Correct |
281 ms |
3424 KB |
Output is correct |
38 |
Correct |
285 ms |
3396 KB |
Output is correct |
39 |
Correct |
370 ms |
3380 KB |
Output is correct |
40 |
Correct |
386 ms |
3448 KB |
Output is correct |
41 |
Correct |
420 ms |
3372 KB |
Output is correct |
42 |
Correct |
361 ms |
3320 KB |
Output is correct |
43 |
Correct |
355 ms |
3524 KB |
Output is correct |
44 |
Correct |
365 ms |
3444 KB |
Output is correct |
45 |
Correct |
365 ms |
3448 KB |
Output is correct |
46 |
Correct |
393 ms |
3244 KB |
Output is correct |
47 |
Correct |
359 ms |
3320 KB |
Output is correct |
48 |
Correct |
369 ms |
3448 KB |
Output is correct |
49 |
Correct |
375 ms |
3320 KB |
Output is correct |
50 |
Correct |
360 ms |
3420 KB |
Output is correct |
51 |
Correct |
111 ms |
2424 KB |
Output is correct |
52 |
Correct |
429 ms |
3576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3320 KB |
Output is correct |
2 |
Correct |
14 ms |
3320 KB |
Output is correct |
3 |
Correct |
6 ms |
2296 KB |
Output is correct |
4 |
Correct |
11 ms |
3320 KB |
Output is correct |
5 |
Correct |
22 ms |
3320 KB |
Output is correct |
6 |
Correct |
16 ms |
3324 KB |
Output is correct |
7 |
Correct |
14 ms |
3320 KB |
Output is correct |
8 |
Correct |
22 ms |
3320 KB |
Output is correct |
9 |
Correct |
19 ms |
3320 KB |
Output is correct |
10 |
Correct |
47 ms |
3324 KB |
Output is correct |
11 |
Correct |
49 ms |
3320 KB |
Output is correct |
12 |
Correct |
47 ms |
3296 KB |
Output is correct |
13 |
Correct |
42 ms |
3448 KB |
Output is correct |
14 |
Correct |
44 ms |
3276 KB |
Output is correct |
15 |
Correct |
45 ms |
3196 KB |
Output is correct |
16 |
Correct |
48 ms |
3320 KB |
Output is correct |
17 |
Correct |
30 ms |
3320 KB |
Output is correct |
18 |
Correct |
39 ms |
3216 KB |
Output is correct |
19 |
Correct |
42 ms |
3320 KB |
Output is correct |
20 |
Correct |
47 ms |
3320 KB |
Output is correct |
21 |
Correct |
96 ms |
3360 KB |
Output is correct |
22 |
Correct |
110 ms |
3280 KB |
Output is correct |
23 |
Correct |
75 ms |
3356 KB |
Output is correct |
24 |
Correct |
137 ms |
3320 KB |
Output is correct |
25 |
Correct |
136 ms |
3320 KB |
Output is correct |
26 |
Correct |
146 ms |
3316 KB |
Output is correct |
27 |
Correct |
145 ms |
3320 KB |
Output is correct |
28 |
Correct |
145 ms |
3324 KB |
Output is correct |
29 |
Correct |
145 ms |
3320 KB |
Output is correct |
30 |
Correct |
143 ms |
3320 KB |
Output is correct |
31 |
Correct |
144 ms |
3396 KB |
Output is correct |
32 |
Correct |
144 ms |
3320 KB |
Output is correct |
33 |
Correct |
145 ms |
3360 KB |
Output is correct |
34 |
Correct |
145 ms |
3320 KB |
Output is correct |
35 |
Correct |
145 ms |
3320 KB |
Output is correct |
36 |
Correct |
145 ms |
3320 KB |
Output is correct |
37 |
Correct |
281 ms |
3424 KB |
Output is correct |
38 |
Correct |
285 ms |
3396 KB |
Output is correct |
39 |
Correct |
370 ms |
3380 KB |
Output is correct |
40 |
Correct |
386 ms |
3448 KB |
Output is correct |
41 |
Correct |
420 ms |
3372 KB |
Output is correct |
42 |
Correct |
361 ms |
3320 KB |
Output is correct |
43 |
Correct |
355 ms |
3524 KB |
Output is correct |
44 |
Correct |
365 ms |
3444 KB |
Output is correct |
45 |
Correct |
365 ms |
3448 KB |
Output is correct |
46 |
Correct |
393 ms |
3244 KB |
Output is correct |
47 |
Correct |
359 ms |
3320 KB |
Output is correct |
48 |
Correct |
369 ms |
3448 KB |
Output is correct |
49 |
Correct |
375 ms |
3320 KB |
Output is correct |
50 |
Correct |
360 ms |
3420 KB |
Output is correct |
51 |
Correct |
111 ms |
2424 KB |
Output is correct |
52 |
Correct |
429 ms |
3576 KB |
Output is correct |
53 |
Correct |
443 ms |
3372 KB |
Output is correct |
54 |
Correct |
507 ms |
3576 KB |
Output is correct |
55 |
Correct |
531 ms |
3652 KB |
Output is correct |
56 |
Correct |
443 ms |
3500 KB |
Output is correct |
57 |
Correct |
538 ms |
3576 KB |
Output is correct |
58 |
Correct |
514 ms |
3576 KB |
Output is correct |
59 |
Correct |
516 ms |
3524 KB |
Output is correct |
60 |
Correct |
154 ms |
2424 KB |
Output is correct |
61 |
Correct |
517 ms |
3448 KB |
Output is correct |
62 |
Correct |
477 ms |
3576 KB |
Output is correct |
63 |
Correct |
485 ms |
3652 KB |
Output is correct |
64 |
Correct |
474 ms |
3704 KB |
Output is correct |
65 |
Correct |
474 ms |
3372 KB |
Output is correct |
66 |
Correct |
467 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3320 KB |
Output is correct |
2 |
Correct |
14 ms |
3320 KB |
Output is correct |
3 |
Correct |
6 ms |
2296 KB |
Output is correct |
4 |
Correct |
11 ms |
3320 KB |
Output is correct |
5 |
Correct |
22 ms |
3320 KB |
Output is correct |
6 |
Correct |
16 ms |
3324 KB |
Output is correct |
7 |
Correct |
14 ms |
3320 KB |
Output is correct |
8 |
Correct |
22 ms |
3320 KB |
Output is correct |
9 |
Correct |
19 ms |
3320 KB |
Output is correct |
10 |
Correct |
47 ms |
3324 KB |
Output is correct |
11 |
Correct |
49 ms |
3320 KB |
Output is correct |
12 |
Correct |
47 ms |
3296 KB |
Output is correct |
13 |
Correct |
42 ms |
3448 KB |
Output is correct |
14 |
Correct |
44 ms |
3276 KB |
Output is correct |
15 |
Correct |
45 ms |
3196 KB |
Output is correct |
16 |
Correct |
48 ms |
3320 KB |
Output is correct |
17 |
Correct |
30 ms |
3320 KB |
Output is correct |
18 |
Correct |
39 ms |
3216 KB |
Output is correct |
19 |
Correct |
42 ms |
3320 KB |
Output is correct |
20 |
Correct |
47 ms |
3320 KB |
Output is correct |
21 |
Correct |
96 ms |
3360 KB |
Output is correct |
22 |
Correct |
110 ms |
3280 KB |
Output is correct |
23 |
Correct |
75 ms |
3356 KB |
Output is correct |
24 |
Correct |
137 ms |
3320 KB |
Output is correct |
25 |
Correct |
136 ms |
3320 KB |
Output is correct |
26 |
Correct |
146 ms |
3316 KB |
Output is correct |
27 |
Correct |
145 ms |
3320 KB |
Output is correct |
28 |
Correct |
145 ms |
3324 KB |
Output is correct |
29 |
Correct |
145 ms |
3320 KB |
Output is correct |
30 |
Correct |
143 ms |
3320 KB |
Output is correct |
31 |
Correct |
144 ms |
3396 KB |
Output is correct |
32 |
Correct |
144 ms |
3320 KB |
Output is correct |
33 |
Correct |
145 ms |
3360 KB |
Output is correct |
34 |
Correct |
145 ms |
3320 KB |
Output is correct |
35 |
Correct |
145 ms |
3320 KB |
Output is correct |
36 |
Correct |
145 ms |
3320 KB |
Output is correct |
37 |
Correct |
281 ms |
3424 KB |
Output is correct |
38 |
Correct |
285 ms |
3396 KB |
Output is correct |
39 |
Correct |
370 ms |
3380 KB |
Output is correct |
40 |
Correct |
386 ms |
3448 KB |
Output is correct |
41 |
Correct |
420 ms |
3372 KB |
Output is correct |
42 |
Correct |
361 ms |
3320 KB |
Output is correct |
43 |
Correct |
355 ms |
3524 KB |
Output is correct |
44 |
Correct |
365 ms |
3444 KB |
Output is correct |
45 |
Correct |
365 ms |
3448 KB |
Output is correct |
46 |
Correct |
393 ms |
3244 KB |
Output is correct |
47 |
Correct |
359 ms |
3320 KB |
Output is correct |
48 |
Correct |
369 ms |
3448 KB |
Output is correct |
49 |
Correct |
375 ms |
3320 KB |
Output is correct |
50 |
Correct |
360 ms |
3420 KB |
Output is correct |
51 |
Correct |
111 ms |
2424 KB |
Output is correct |
52 |
Correct |
429 ms |
3576 KB |
Output is correct |
53 |
Correct |
443 ms |
3372 KB |
Output is correct |
54 |
Correct |
507 ms |
3576 KB |
Output is correct |
55 |
Correct |
531 ms |
3652 KB |
Output is correct |
56 |
Correct |
443 ms |
3500 KB |
Output is correct |
57 |
Correct |
538 ms |
3576 KB |
Output is correct |
58 |
Correct |
514 ms |
3576 KB |
Output is correct |
59 |
Correct |
516 ms |
3524 KB |
Output is correct |
60 |
Correct |
154 ms |
2424 KB |
Output is correct |
61 |
Correct |
517 ms |
3448 KB |
Output is correct |
62 |
Correct |
477 ms |
3576 KB |
Output is correct |
63 |
Correct |
485 ms |
3652 KB |
Output is correct |
64 |
Correct |
474 ms |
3704 KB |
Output is correct |
65 |
Correct |
474 ms |
3372 KB |
Output is correct |
66 |
Correct |
467 ms |
3320 KB |
Output is correct |
67 |
Correct |
592 ms |
3496 KB |
Output is correct |
68 |
Correct |
219 ms |
2296 KB |
Output is correct |
69 |
Correct |
799 ms |
3960 KB |
Output is correct |
70 |
Correct |
757 ms |
3832 KB |
Output is correct |
71 |
Correct |
756 ms |
3756 KB |
Output is correct |
72 |
Correct |
752 ms |
3320 KB |
Output is correct |
73 |
Correct |
755 ms |
3244 KB |
Output is correct |
74 |
Correct |
805 ms |
4088 KB |
Output is correct |
75 |
Correct |
776 ms |
3888 KB |
Output is correct |
76 |
Correct |
839 ms |
3960 KB |
Output is correct |
77 |
Correct |
815 ms |
4088 KB |
Output is correct |