#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include"bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
// #define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991
const int maxn = 271;
bool dp[maxn][maxn*maxn];
bitset<maxn*maxn> ans;
int n, tot, ex=-1, total;
int a[maxn];
void rec () {
for (int i = n ; i >= 0 ; i--) {
for (int j = 0 ; j <= total ; j++) {
if (i == n) dp[i][j] = j == 0;
else if (i == ex) dp[i][j] = dp[i + 1][j];
else dp[i][j] = dp[i + 1][j] || (j - a[i] < 0 ? 0 : dp[i + 1][j - a[i]]);
}
}
// if (sm < 0) return 0;
// if (i == n) return sm == 0;
// if (i == ex) return rec(i + 1, sm);
// if (dp[i][sm] != -1) return dp[i][sm];
// return dp[i][sm] = rec(i + 1, sm) | rec(i + 1, sm - a[i]);
}
signed main () {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 0 ; i < n ; i++) cin >> a[i], total += a[i];
for (int i = 0 ; i <= total ; i++) ans[i] = 1;
rec();
if (!dp[0][total/2]) {
cout << 0 << endl;
return 0;
}
// cerr << "here\n";
ans[0] = 0;
for (int i = 0 ; i < n ; i++) {
tot = total - a[i];
ex = i;
rec();
for (int j = 1 ; j <= total ; j++) {
if ((tot+j)&1||!dp[0][(tot+j)/2]) {
ans[j] = 0;
}
}
}
cout << ans.count() << endl;
for (int i = 0 ; i <= total ; i++) if (ans[i]) cout << i << " ";
}
Compilation message
bootfall.cpp:17:1: warning: multi-line comment [-Wcomment]
17 | //\
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
17 ms |
804 KB |
Output is correct |
22 |
Correct |
21 ms |
892 KB |
Output is correct |
23 |
Correct |
7 ms |
664 KB |
Output is correct |
24 |
Correct |
50 ms |
1128 KB |
Output is correct |
25 |
Correct |
89 ms |
1536 KB |
Output is correct |
26 |
Correct |
101 ms |
1620 KB |
Output is correct |
27 |
Correct |
101 ms |
1600 KB |
Output is correct |
28 |
Correct |
111 ms |
1660 KB |
Output is correct |
29 |
Correct |
115 ms |
1688 KB |
Output is correct |
30 |
Correct |
50 ms |
1244 KB |
Output is correct |
31 |
Correct |
77 ms |
1468 KB |
Output is correct |
32 |
Correct |
47 ms |
1200 KB |
Output is correct |
33 |
Correct |
112 ms |
1776 KB |
Output is correct |
34 |
Correct |
129 ms |
1620 KB |
Output is correct |
35 |
Correct |
130 ms |
1688 KB |
Output is correct |
36 |
Correct |
45 ms |
1188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
17 ms |
804 KB |
Output is correct |
22 |
Correct |
21 ms |
892 KB |
Output is correct |
23 |
Correct |
7 ms |
664 KB |
Output is correct |
24 |
Correct |
50 ms |
1128 KB |
Output is correct |
25 |
Correct |
89 ms |
1536 KB |
Output is correct |
26 |
Correct |
101 ms |
1620 KB |
Output is correct |
27 |
Correct |
101 ms |
1600 KB |
Output is correct |
28 |
Correct |
111 ms |
1660 KB |
Output is correct |
29 |
Correct |
115 ms |
1688 KB |
Output is correct |
30 |
Correct |
50 ms |
1244 KB |
Output is correct |
31 |
Correct |
77 ms |
1468 KB |
Output is correct |
32 |
Correct |
47 ms |
1200 KB |
Output is correct |
33 |
Correct |
112 ms |
1776 KB |
Output is correct |
34 |
Correct |
129 ms |
1620 KB |
Output is correct |
35 |
Correct |
130 ms |
1688 KB |
Output is correct |
36 |
Correct |
45 ms |
1188 KB |
Output is correct |
37 |
Correct |
695 ms |
4948 KB |
Output is correct |
38 |
Correct |
743 ms |
5056 KB |
Output is correct |
39 |
Execution timed out |
1096 ms |
16316 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
17 ms |
804 KB |
Output is correct |
22 |
Correct |
21 ms |
892 KB |
Output is correct |
23 |
Correct |
7 ms |
664 KB |
Output is correct |
24 |
Correct |
50 ms |
1128 KB |
Output is correct |
25 |
Correct |
89 ms |
1536 KB |
Output is correct |
26 |
Correct |
101 ms |
1620 KB |
Output is correct |
27 |
Correct |
101 ms |
1600 KB |
Output is correct |
28 |
Correct |
111 ms |
1660 KB |
Output is correct |
29 |
Correct |
115 ms |
1688 KB |
Output is correct |
30 |
Correct |
50 ms |
1244 KB |
Output is correct |
31 |
Correct |
77 ms |
1468 KB |
Output is correct |
32 |
Correct |
47 ms |
1200 KB |
Output is correct |
33 |
Correct |
112 ms |
1776 KB |
Output is correct |
34 |
Correct |
129 ms |
1620 KB |
Output is correct |
35 |
Correct |
130 ms |
1688 KB |
Output is correct |
36 |
Correct |
45 ms |
1188 KB |
Output is correct |
37 |
Correct |
695 ms |
4948 KB |
Output is correct |
38 |
Correct |
743 ms |
5056 KB |
Output is correct |
39 |
Execution timed out |
1096 ms |
16316 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
17 ms |
804 KB |
Output is correct |
22 |
Correct |
21 ms |
892 KB |
Output is correct |
23 |
Correct |
7 ms |
664 KB |
Output is correct |
24 |
Correct |
50 ms |
1128 KB |
Output is correct |
25 |
Correct |
89 ms |
1536 KB |
Output is correct |
26 |
Correct |
101 ms |
1620 KB |
Output is correct |
27 |
Correct |
101 ms |
1600 KB |
Output is correct |
28 |
Correct |
111 ms |
1660 KB |
Output is correct |
29 |
Correct |
115 ms |
1688 KB |
Output is correct |
30 |
Correct |
50 ms |
1244 KB |
Output is correct |
31 |
Correct |
77 ms |
1468 KB |
Output is correct |
32 |
Correct |
47 ms |
1200 KB |
Output is correct |
33 |
Correct |
112 ms |
1776 KB |
Output is correct |
34 |
Correct |
129 ms |
1620 KB |
Output is correct |
35 |
Correct |
130 ms |
1688 KB |
Output is correct |
36 |
Correct |
45 ms |
1188 KB |
Output is correct |
37 |
Correct |
695 ms |
4948 KB |
Output is correct |
38 |
Correct |
743 ms |
5056 KB |
Output is correct |
39 |
Execution timed out |
1096 ms |
16316 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |