#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
using ll = long long;
//#define int ll
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);
//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return uniform_int_distribution<int> (l, r)(rng); }
int n, a[555], pref[555], sum[555];
bitset <122550> dp[505], ans, cur[505];
main() {
file("paint");
ios;
cin >> n;
fo(i, 1, n, 1) cin >> a[i], pref[i] = pref[i - 1] + a[i];
fo(i, 1, n, 1) sum[i] = pref[i - 1] + pref[n] - pref[i];
fo(i, 0, 122500, 1) ans.set(i);
fo(i, 1, n + 1, 1) {
bool t = 0;
fo(j, 1, n, 1) {
if (i != j) {
if (!t) {
dp[i][a[j]]=dp[i][0]=1;
t = 1;
continue;
}
dp[i] |= ((dp[i] << a[j]));
}
}
if (i == n + 1) {
if (pref[n] % 2 || !dp[i].test(pref[n] / 2)) return !(cout << "0");
break;
}
fo(j, 0, 122500, 1) if (dp[i].test(j)) {
int left = sum[i] - j;
cur[i][abs(j - left)] = 1;
}
ans &= cur[i];
}
cout << ans.count() << "\n";
fo(i, 0, 122500, 1) if (ans.test(i)) cout << i << " ";
return 0;
}
/**
500000
250000
4
1 3 1 5
6
3 5 7 11 9 13
3
2 2 2
*/
Compilation message
bootfall.cpp:63:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
63 | main() {
| ^
bootfall.cpp: In function 'int main()':
bootfall.cpp:23:48: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
23 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
bootfall.cpp:64:3: note: in expansion of macro 'file'
64 | file("paint");
| ^~~~
bootfall.cpp:23:77: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
23 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:64:3: note: in expansion of macro 'file'
64 | file("paint");
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
7 ms |
972 KB |
Output is correct |
11 |
Correct |
7 ms |
844 KB |
Output is correct |
12 |
Correct |
7 ms |
972 KB |
Output is correct |
13 |
Correct |
7 ms |
840 KB |
Output is correct |
14 |
Correct |
8 ms |
824 KB |
Output is correct |
15 |
Correct |
8 ms |
844 KB |
Output is correct |
16 |
Correct |
7 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
720 KB |
Output is correct |
18 |
Correct |
5 ms |
844 KB |
Output is correct |
19 |
Correct |
6 ms |
844 KB |
Output is correct |
20 |
Correct |
7 ms |
960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
7 ms |
972 KB |
Output is correct |
11 |
Correct |
7 ms |
844 KB |
Output is correct |
12 |
Correct |
7 ms |
972 KB |
Output is correct |
13 |
Correct |
7 ms |
840 KB |
Output is correct |
14 |
Correct |
8 ms |
824 KB |
Output is correct |
15 |
Correct |
8 ms |
844 KB |
Output is correct |
16 |
Correct |
7 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
720 KB |
Output is correct |
18 |
Correct |
5 ms |
844 KB |
Output is correct |
19 |
Correct |
6 ms |
844 KB |
Output is correct |
20 |
Correct |
7 ms |
960 KB |
Output is correct |
21 |
Correct |
23 ms |
1616 KB |
Output is correct |
22 |
Correct |
31 ms |
1800 KB |
Output is correct |
23 |
Correct |
17 ms |
1324 KB |
Output is correct |
24 |
Correct |
46 ms |
2204 KB |
Output is correct |
25 |
Correct |
46 ms |
2244 KB |
Output is correct |
26 |
Correct |
53 ms |
2368 KB |
Output is correct |
27 |
Correct |
52 ms |
2388 KB |
Output is correct |
28 |
Correct |
51 ms |
2296 KB |
Output is correct |
29 |
Correct |
51 ms |
2352 KB |
Output is correct |
30 |
Correct |
54 ms |
2264 KB |
Output is correct |
31 |
Correct |
54 ms |
2288 KB |
Output is correct |
32 |
Correct |
51 ms |
2288 KB |
Output is correct |
33 |
Correct |
49 ms |
2508 KB |
Output is correct |
34 |
Correct |
54 ms |
2376 KB |
Output is correct |
35 |
Correct |
50 ms |
2340 KB |
Output is correct |
36 |
Correct |
52 ms |
2316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
7 ms |
972 KB |
Output is correct |
11 |
Correct |
7 ms |
844 KB |
Output is correct |
12 |
Correct |
7 ms |
972 KB |
Output is correct |
13 |
Correct |
7 ms |
840 KB |
Output is correct |
14 |
Correct |
8 ms |
824 KB |
Output is correct |
15 |
Correct |
8 ms |
844 KB |
Output is correct |
16 |
Correct |
7 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
720 KB |
Output is correct |
18 |
Correct |
5 ms |
844 KB |
Output is correct |
19 |
Correct |
6 ms |
844 KB |
Output is correct |
20 |
Correct |
7 ms |
960 KB |
Output is correct |
21 |
Correct |
23 ms |
1616 KB |
Output is correct |
22 |
Correct |
31 ms |
1800 KB |
Output is correct |
23 |
Correct |
17 ms |
1324 KB |
Output is correct |
24 |
Correct |
46 ms |
2204 KB |
Output is correct |
25 |
Correct |
46 ms |
2244 KB |
Output is correct |
26 |
Correct |
53 ms |
2368 KB |
Output is correct |
27 |
Correct |
52 ms |
2388 KB |
Output is correct |
28 |
Correct |
51 ms |
2296 KB |
Output is correct |
29 |
Correct |
51 ms |
2352 KB |
Output is correct |
30 |
Correct |
54 ms |
2264 KB |
Output is correct |
31 |
Correct |
54 ms |
2288 KB |
Output is correct |
32 |
Correct |
51 ms |
2288 KB |
Output is correct |
33 |
Correct |
49 ms |
2508 KB |
Output is correct |
34 |
Correct |
54 ms |
2376 KB |
Output is correct |
35 |
Correct |
50 ms |
2340 KB |
Output is correct |
36 |
Correct |
52 ms |
2316 KB |
Output is correct |
37 |
Correct |
193 ms |
4644 KB |
Output is correct |
38 |
Correct |
200 ms |
4596 KB |
Output is correct |
39 |
Correct |
263 ms |
6940 KB |
Output is correct |
40 |
Correct |
390 ms |
6864 KB |
Output is correct |
41 |
Correct |
295 ms |
7784 KB |
Output is correct |
42 |
Correct |
297 ms |
6076 KB |
Output is correct |
43 |
Correct |
311 ms |
6764 KB |
Output is correct |
44 |
Correct |
322 ms |
6840 KB |
Output is correct |
45 |
Correct |
341 ms |
6980 KB |
Output is correct |
46 |
Correct |
319 ms |
6456 KB |
Output is correct |
47 |
Correct |
313 ms |
6184 KB |
Output is correct |
48 |
Correct |
314 ms |
7008 KB |
Output is correct |
49 |
Correct |
290 ms |
6980 KB |
Output is correct |
50 |
Correct |
307 ms |
6212 KB |
Output is correct |
51 |
Correct |
296 ms |
6080 KB |
Output is correct |
52 |
Correct |
373 ms |
7876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
7 ms |
972 KB |
Output is correct |
11 |
Correct |
7 ms |
844 KB |
Output is correct |
12 |
Correct |
7 ms |
972 KB |
Output is correct |
13 |
Correct |
7 ms |
840 KB |
Output is correct |
14 |
Correct |
8 ms |
824 KB |
Output is correct |
15 |
Correct |
8 ms |
844 KB |
Output is correct |
16 |
Correct |
7 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
720 KB |
Output is correct |
18 |
Correct |
5 ms |
844 KB |
Output is correct |
19 |
Correct |
6 ms |
844 KB |
Output is correct |
20 |
Correct |
7 ms |
960 KB |
Output is correct |
21 |
Correct |
23 ms |
1616 KB |
Output is correct |
22 |
Correct |
31 ms |
1800 KB |
Output is correct |
23 |
Correct |
17 ms |
1324 KB |
Output is correct |
24 |
Correct |
46 ms |
2204 KB |
Output is correct |
25 |
Correct |
46 ms |
2244 KB |
Output is correct |
26 |
Correct |
53 ms |
2368 KB |
Output is correct |
27 |
Correct |
52 ms |
2388 KB |
Output is correct |
28 |
Correct |
51 ms |
2296 KB |
Output is correct |
29 |
Correct |
51 ms |
2352 KB |
Output is correct |
30 |
Correct |
54 ms |
2264 KB |
Output is correct |
31 |
Correct |
54 ms |
2288 KB |
Output is correct |
32 |
Correct |
51 ms |
2288 KB |
Output is correct |
33 |
Correct |
49 ms |
2508 KB |
Output is correct |
34 |
Correct |
54 ms |
2376 KB |
Output is correct |
35 |
Correct |
50 ms |
2340 KB |
Output is correct |
36 |
Correct |
52 ms |
2316 KB |
Output is correct |
37 |
Correct |
193 ms |
4644 KB |
Output is correct |
38 |
Correct |
200 ms |
4596 KB |
Output is correct |
39 |
Correct |
263 ms |
6940 KB |
Output is correct |
40 |
Correct |
390 ms |
6864 KB |
Output is correct |
41 |
Correct |
295 ms |
7784 KB |
Output is correct |
42 |
Correct |
297 ms |
6076 KB |
Output is correct |
43 |
Correct |
311 ms |
6764 KB |
Output is correct |
44 |
Correct |
322 ms |
6840 KB |
Output is correct |
45 |
Correct |
341 ms |
6980 KB |
Output is correct |
46 |
Correct |
319 ms |
6456 KB |
Output is correct |
47 |
Correct |
313 ms |
6184 KB |
Output is correct |
48 |
Correct |
314 ms |
7008 KB |
Output is correct |
49 |
Correct |
290 ms |
6980 KB |
Output is correct |
50 |
Correct |
307 ms |
6212 KB |
Output is correct |
51 |
Correct |
296 ms |
6080 KB |
Output is correct |
52 |
Correct |
373 ms |
7876 KB |
Output is correct |
53 |
Correct |
437 ms |
7856 KB |
Output is correct |
54 |
Correct |
599 ms |
9452 KB |
Output is correct |
55 |
Correct |
656 ms |
11052 KB |
Output is correct |
56 |
Correct |
463 ms |
8348 KB |
Output is correct |
57 |
Correct |
668 ms |
11204 KB |
Output is correct |
58 |
Correct |
621 ms |
9760 KB |
Output is correct |
59 |
Correct |
625 ms |
10596 KB |
Output is correct |
60 |
Correct |
594 ms |
9692 KB |
Output is correct |
61 |
Correct |
634 ms |
10960 KB |
Output is correct |
62 |
Correct |
552 ms |
10400 KB |
Output is correct |
63 |
Correct |
556 ms |
10364 KB |
Output is correct |
64 |
Correct |
536 ms |
10024 KB |
Output is correct |
65 |
Correct |
416 ms |
8132 KB |
Output is correct |
66 |
Correct |
398 ms |
8264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
7 ms |
972 KB |
Output is correct |
11 |
Correct |
7 ms |
844 KB |
Output is correct |
12 |
Correct |
7 ms |
972 KB |
Output is correct |
13 |
Correct |
7 ms |
840 KB |
Output is correct |
14 |
Correct |
8 ms |
824 KB |
Output is correct |
15 |
Correct |
8 ms |
844 KB |
Output is correct |
16 |
Correct |
7 ms |
844 KB |
Output is correct |
17 |
Correct |
4 ms |
720 KB |
Output is correct |
18 |
Correct |
5 ms |
844 KB |
Output is correct |
19 |
Correct |
6 ms |
844 KB |
Output is correct |
20 |
Correct |
7 ms |
960 KB |
Output is correct |
21 |
Correct |
23 ms |
1616 KB |
Output is correct |
22 |
Correct |
31 ms |
1800 KB |
Output is correct |
23 |
Correct |
17 ms |
1324 KB |
Output is correct |
24 |
Correct |
46 ms |
2204 KB |
Output is correct |
25 |
Correct |
46 ms |
2244 KB |
Output is correct |
26 |
Correct |
53 ms |
2368 KB |
Output is correct |
27 |
Correct |
52 ms |
2388 KB |
Output is correct |
28 |
Correct |
51 ms |
2296 KB |
Output is correct |
29 |
Correct |
51 ms |
2352 KB |
Output is correct |
30 |
Correct |
54 ms |
2264 KB |
Output is correct |
31 |
Correct |
54 ms |
2288 KB |
Output is correct |
32 |
Correct |
51 ms |
2288 KB |
Output is correct |
33 |
Correct |
49 ms |
2508 KB |
Output is correct |
34 |
Correct |
54 ms |
2376 KB |
Output is correct |
35 |
Correct |
50 ms |
2340 KB |
Output is correct |
36 |
Correct |
52 ms |
2316 KB |
Output is correct |
37 |
Correct |
193 ms |
4644 KB |
Output is correct |
38 |
Correct |
200 ms |
4596 KB |
Output is correct |
39 |
Correct |
263 ms |
6940 KB |
Output is correct |
40 |
Correct |
390 ms |
6864 KB |
Output is correct |
41 |
Correct |
295 ms |
7784 KB |
Output is correct |
42 |
Correct |
297 ms |
6076 KB |
Output is correct |
43 |
Correct |
311 ms |
6764 KB |
Output is correct |
44 |
Correct |
322 ms |
6840 KB |
Output is correct |
45 |
Correct |
341 ms |
6980 KB |
Output is correct |
46 |
Correct |
319 ms |
6456 KB |
Output is correct |
47 |
Correct |
313 ms |
6184 KB |
Output is correct |
48 |
Correct |
314 ms |
7008 KB |
Output is correct |
49 |
Correct |
290 ms |
6980 KB |
Output is correct |
50 |
Correct |
307 ms |
6212 KB |
Output is correct |
51 |
Correct |
296 ms |
6080 KB |
Output is correct |
52 |
Correct |
373 ms |
7876 KB |
Output is correct |
53 |
Correct |
437 ms |
7856 KB |
Output is correct |
54 |
Correct |
599 ms |
9452 KB |
Output is correct |
55 |
Correct |
656 ms |
11052 KB |
Output is correct |
56 |
Correct |
463 ms |
8348 KB |
Output is correct |
57 |
Correct |
668 ms |
11204 KB |
Output is correct |
58 |
Correct |
621 ms |
9760 KB |
Output is correct |
59 |
Correct |
625 ms |
10596 KB |
Output is correct |
60 |
Correct |
594 ms |
9692 KB |
Output is correct |
61 |
Correct |
634 ms |
10960 KB |
Output is correct |
62 |
Correct |
552 ms |
10400 KB |
Output is correct |
63 |
Correct |
556 ms |
10364 KB |
Output is correct |
64 |
Correct |
536 ms |
10024 KB |
Output is correct |
65 |
Correct |
416 ms |
8132 KB |
Output is correct |
66 |
Correct |
398 ms |
8264 KB |
Output is correct |
67 |
Correct |
799 ms |
12028 KB |
Output is correct |
68 |
Execution timed out |
1080 ms |
15104 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |