#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
bitset <501*501*2>dp[505], dp2[505];
int n, A[505];
const int os = 500 * 500;
bool chk(int a, int b){
if(os - a - b >= 0 && dp[n & 1][os - a - b])return 1;
if(os - a + b >= 0 && os - a + b <= 2 * os && dp[n & 1][os - a + b])return 1;
if(os + a - b >= 0 && os + a - b <= 2 * os && dp[n & 1][os + a - b])return 1;
if(os + a + b <= 2 * os && dp[n & 1][os + a + b])return 1;
return 0;
}
void solve(){
cin >> n;
for(int i = 1; i <= n; i++)cin >> A[i];
//for(int i = 0; i <= 2 * os; i++)dp[0][i] = 0
dp[0][os] = dp2[n + 1][os] = 1;
for(int i = 1; i <= n; i++){
dp[i] |= (dp[i - 1] >> A[i]);
dp[i] |= (dp[i - 1] << A[i]);
}
for(int i = n; i >= 1; i--){
dp2[i] |= (dp2[i + 1] >> A[i]);
dp2[i] |= (dp2[i + 1] << A[i]);
}
if(!dp[n][os]){
cout << 0;
return;
}
set <int> s;
for(int i = 1; i <= os; i++)s.insert(i);
for(int i = 1; i <= n; i++){
/*
bitset <501*501*2> tmp = dp[i - 1], tmp2;
for(int j = 0; j <= os; j++){
if(dp2[i + 1][os - j] || dp2[i + 1][os + j]){
if(1)tmp2 |= (tmp >> j), tmp2 |= (tmp << j);
}
}
*/
bitset <501 * 501 * 2> tmp;
tmp[os] = 1;
for(int j = 1; j <= n; j++){
if(j == i)continue;
tmp = (tmp >> A[j]) | (tmp << A[j]);
}
for(int j = 0; j <= os; j++)if(!tmp[os - j] && !tmp[os + j])s.erase(j);
}
cout << (int)s.size() << '\n';
for(auto i : s)cout << i << ' ';
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message
bootfall.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
66 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
16468 KB |
Output is correct |
2 |
Correct |
59 ms |
16464 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
58 ms |
16648 KB |
Output is correct |
5 |
Correct |
81 ms |
16652 KB |
Output is correct |
6 |
Correct |
62 ms |
16532 KB |
Output is correct |
7 |
Correct |
58 ms |
16648 KB |
Output is correct |
8 |
Correct |
72 ms |
16468 KB |
Output is correct |
9 |
Correct |
67 ms |
16464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
16468 KB |
Output is correct |
2 |
Correct |
59 ms |
16464 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
58 ms |
16648 KB |
Output is correct |
5 |
Correct |
81 ms |
16652 KB |
Output is correct |
6 |
Correct |
62 ms |
16532 KB |
Output is correct |
7 |
Correct |
58 ms |
16648 KB |
Output is correct |
8 |
Correct |
72 ms |
16468 KB |
Output is correct |
9 |
Correct |
67 ms |
16464 KB |
Output is correct |
10 |
Correct |
110 ms |
16720 KB |
Output is correct |
11 |
Correct |
112 ms |
16468 KB |
Output is correct |
12 |
Correct |
109 ms |
16476 KB |
Output is correct |
13 |
Correct |
100 ms |
16468 KB |
Output is correct |
14 |
Correct |
113 ms |
16468 KB |
Output is correct |
15 |
Correct |
116 ms |
16648 KB |
Output is correct |
16 |
Correct |
118 ms |
16412 KB |
Output is correct |
17 |
Correct |
84 ms |
16468 KB |
Output is correct |
18 |
Correct |
97 ms |
16644 KB |
Output is correct |
19 |
Correct |
110 ms |
16648 KB |
Output is correct |
20 |
Correct |
105 ms |
16648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
16468 KB |
Output is correct |
2 |
Correct |
59 ms |
16464 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
58 ms |
16648 KB |
Output is correct |
5 |
Correct |
81 ms |
16652 KB |
Output is correct |
6 |
Correct |
62 ms |
16532 KB |
Output is correct |
7 |
Correct |
58 ms |
16648 KB |
Output is correct |
8 |
Correct |
72 ms |
16468 KB |
Output is correct |
9 |
Correct |
67 ms |
16464 KB |
Output is correct |
10 |
Correct |
110 ms |
16720 KB |
Output is correct |
11 |
Correct |
112 ms |
16468 KB |
Output is correct |
12 |
Correct |
109 ms |
16476 KB |
Output is correct |
13 |
Correct |
100 ms |
16468 KB |
Output is correct |
14 |
Correct |
113 ms |
16468 KB |
Output is correct |
15 |
Correct |
116 ms |
16648 KB |
Output is correct |
16 |
Correct |
118 ms |
16412 KB |
Output is correct |
17 |
Correct |
84 ms |
16468 KB |
Output is correct |
18 |
Correct |
97 ms |
16644 KB |
Output is correct |
19 |
Correct |
110 ms |
16648 KB |
Output is correct |
20 |
Correct |
105 ms |
16648 KB |
Output is correct |
21 |
Correct |
279 ms |
20748 KB |
Output is correct |
22 |
Correct |
338 ms |
24852 KB |
Output is correct |
23 |
Correct |
213 ms |
20564 KB |
Output is correct |
24 |
Correct |
500 ms |
24860 KB |
Output is correct |
25 |
Correct |
495 ms |
24660 KB |
Output is correct |
26 |
Correct |
527 ms |
26916 KB |
Output is correct |
27 |
Correct |
494 ms |
26960 KB |
Output is correct |
28 |
Correct |
484 ms |
26904 KB |
Output is correct |
29 |
Correct |
468 ms |
26892 KB |
Output is correct |
30 |
Correct |
402 ms |
26704 KB |
Output is correct |
31 |
Correct |
503 ms |
26708 KB |
Output is correct |
32 |
Correct |
522 ms |
26912 KB |
Output is correct |
33 |
Correct |
433 ms |
27160 KB |
Output is correct |
34 |
Correct |
429 ms |
26704 KB |
Output is correct |
35 |
Correct |
434 ms |
26908 KB |
Output is correct |
36 |
Correct |
498 ms |
26908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
16468 KB |
Output is correct |
2 |
Correct |
59 ms |
16464 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
58 ms |
16648 KB |
Output is correct |
5 |
Correct |
81 ms |
16652 KB |
Output is correct |
6 |
Correct |
62 ms |
16532 KB |
Output is correct |
7 |
Correct |
58 ms |
16648 KB |
Output is correct |
8 |
Correct |
72 ms |
16468 KB |
Output is correct |
9 |
Correct |
67 ms |
16464 KB |
Output is correct |
10 |
Correct |
110 ms |
16720 KB |
Output is correct |
11 |
Correct |
112 ms |
16468 KB |
Output is correct |
12 |
Correct |
109 ms |
16476 KB |
Output is correct |
13 |
Correct |
100 ms |
16468 KB |
Output is correct |
14 |
Correct |
113 ms |
16468 KB |
Output is correct |
15 |
Correct |
116 ms |
16648 KB |
Output is correct |
16 |
Correct |
118 ms |
16412 KB |
Output is correct |
17 |
Correct |
84 ms |
16468 KB |
Output is correct |
18 |
Correct |
97 ms |
16644 KB |
Output is correct |
19 |
Correct |
110 ms |
16648 KB |
Output is correct |
20 |
Correct |
105 ms |
16648 KB |
Output is correct |
21 |
Correct |
279 ms |
20748 KB |
Output is correct |
22 |
Correct |
338 ms |
24852 KB |
Output is correct |
23 |
Correct |
213 ms |
20564 KB |
Output is correct |
24 |
Correct |
500 ms |
24860 KB |
Output is correct |
25 |
Correct |
495 ms |
24660 KB |
Output is correct |
26 |
Correct |
527 ms |
26916 KB |
Output is correct |
27 |
Correct |
494 ms |
26960 KB |
Output is correct |
28 |
Correct |
484 ms |
26904 KB |
Output is correct |
29 |
Correct |
468 ms |
26892 KB |
Output is correct |
30 |
Correct |
402 ms |
26704 KB |
Output is correct |
31 |
Correct |
503 ms |
26708 KB |
Output is correct |
32 |
Correct |
522 ms |
26912 KB |
Output is correct |
33 |
Correct |
433 ms |
27160 KB |
Output is correct |
34 |
Correct |
429 ms |
26704 KB |
Output is correct |
35 |
Correct |
434 ms |
26908 KB |
Output is correct |
36 |
Correct |
498 ms |
26908 KB |
Output is correct |
37 |
Execution timed out |
1075 ms |
38996 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
16468 KB |
Output is correct |
2 |
Correct |
59 ms |
16464 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
58 ms |
16648 KB |
Output is correct |
5 |
Correct |
81 ms |
16652 KB |
Output is correct |
6 |
Correct |
62 ms |
16532 KB |
Output is correct |
7 |
Correct |
58 ms |
16648 KB |
Output is correct |
8 |
Correct |
72 ms |
16468 KB |
Output is correct |
9 |
Correct |
67 ms |
16464 KB |
Output is correct |
10 |
Correct |
110 ms |
16720 KB |
Output is correct |
11 |
Correct |
112 ms |
16468 KB |
Output is correct |
12 |
Correct |
109 ms |
16476 KB |
Output is correct |
13 |
Correct |
100 ms |
16468 KB |
Output is correct |
14 |
Correct |
113 ms |
16468 KB |
Output is correct |
15 |
Correct |
116 ms |
16648 KB |
Output is correct |
16 |
Correct |
118 ms |
16412 KB |
Output is correct |
17 |
Correct |
84 ms |
16468 KB |
Output is correct |
18 |
Correct |
97 ms |
16644 KB |
Output is correct |
19 |
Correct |
110 ms |
16648 KB |
Output is correct |
20 |
Correct |
105 ms |
16648 KB |
Output is correct |
21 |
Correct |
279 ms |
20748 KB |
Output is correct |
22 |
Correct |
338 ms |
24852 KB |
Output is correct |
23 |
Correct |
213 ms |
20564 KB |
Output is correct |
24 |
Correct |
500 ms |
24860 KB |
Output is correct |
25 |
Correct |
495 ms |
24660 KB |
Output is correct |
26 |
Correct |
527 ms |
26916 KB |
Output is correct |
27 |
Correct |
494 ms |
26960 KB |
Output is correct |
28 |
Correct |
484 ms |
26904 KB |
Output is correct |
29 |
Correct |
468 ms |
26892 KB |
Output is correct |
30 |
Correct |
402 ms |
26704 KB |
Output is correct |
31 |
Correct |
503 ms |
26708 KB |
Output is correct |
32 |
Correct |
522 ms |
26912 KB |
Output is correct |
33 |
Correct |
433 ms |
27160 KB |
Output is correct |
34 |
Correct |
429 ms |
26704 KB |
Output is correct |
35 |
Correct |
434 ms |
26908 KB |
Output is correct |
36 |
Correct |
498 ms |
26908 KB |
Output is correct |
37 |
Execution timed out |
1075 ms |
38996 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
16468 KB |
Output is correct |
2 |
Correct |
59 ms |
16464 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
58 ms |
16648 KB |
Output is correct |
5 |
Correct |
81 ms |
16652 KB |
Output is correct |
6 |
Correct |
62 ms |
16532 KB |
Output is correct |
7 |
Correct |
58 ms |
16648 KB |
Output is correct |
8 |
Correct |
72 ms |
16468 KB |
Output is correct |
9 |
Correct |
67 ms |
16464 KB |
Output is correct |
10 |
Correct |
110 ms |
16720 KB |
Output is correct |
11 |
Correct |
112 ms |
16468 KB |
Output is correct |
12 |
Correct |
109 ms |
16476 KB |
Output is correct |
13 |
Correct |
100 ms |
16468 KB |
Output is correct |
14 |
Correct |
113 ms |
16468 KB |
Output is correct |
15 |
Correct |
116 ms |
16648 KB |
Output is correct |
16 |
Correct |
118 ms |
16412 KB |
Output is correct |
17 |
Correct |
84 ms |
16468 KB |
Output is correct |
18 |
Correct |
97 ms |
16644 KB |
Output is correct |
19 |
Correct |
110 ms |
16648 KB |
Output is correct |
20 |
Correct |
105 ms |
16648 KB |
Output is correct |
21 |
Correct |
279 ms |
20748 KB |
Output is correct |
22 |
Correct |
338 ms |
24852 KB |
Output is correct |
23 |
Correct |
213 ms |
20564 KB |
Output is correct |
24 |
Correct |
500 ms |
24860 KB |
Output is correct |
25 |
Correct |
495 ms |
24660 KB |
Output is correct |
26 |
Correct |
527 ms |
26916 KB |
Output is correct |
27 |
Correct |
494 ms |
26960 KB |
Output is correct |
28 |
Correct |
484 ms |
26904 KB |
Output is correct |
29 |
Correct |
468 ms |
26892 KB |
Output is correct |
30 |
Correct |
402 ms |
26704 KB |
Output is correct |
31 |
Correct |
503 ms |
26708 KB |
Output is correct |
32 |
Correct |
522 ms |
26912 KB |
Output is correct |
33 |
Correct |
433 ms |
27160 KB |
Output is correct |
34 |
Correct |
429 ms |
26704 KB |
Output is correct |
35 |
Correct |
434 ms |
26908 KB |
Output is correct |
36 |
Correct |
498 ms |
26908 KB |
Output is correct |
37 |
Execution timed out |
1075 ms |
38996 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |