#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
const int MAXN = 100;
#pragma GCC optimize("O3")
const int MAXSUM = 500 * 500;
typedef bitset<MAXSUM+1> bit;
bit f(VI& v, int excludant = -1) {
bit ans;
ans[0] = 1;
rep(i, v.size()) {
if (i == excludant) continue;
ans |= (ans << v[i]);
}
return ans;
}
void solve() {
int n;
cin >> n;
VI a(n);
int sum = 0;
for (int& x : a) cin >> x, sum += x;
bit pos = f(a);
if (sum % 2 || !pos[sum/2]) cout << 0 << endl;
else {
bit ans = ~bit(0);
rep(i, n) {
bit pos = f(a, i);
for (int x = 0; x <= MAXSUM; x++) {
int newsum = (sum - a[i] + x);
if (newsum % 2 || newsum/2 < x || (!pos[newsum/2] && !pos[newsum/2 - x])) {
ans[x] = false;
}
}
}
VI v;
for (int i = 0; i <= MAXSUM; i++) {
if (ans[i]) v.pb(i);
}
cout << v.size() << endl;
for (int x : v) cout << x << " ";
cout << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
600 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
600 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
20 ms |
848 KB |
Output is correct |
11 |
Correct |
19 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
348 KB |
Output is correct |
13 |
Correct |
15 ms |
344 KB |
Output is correct |
14 |
Correct |
16 ms |
608 KB |
Output is correct |
15 |
Correct |
16 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
600 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
348 KB |
Output is correct |
20 |
Correct |
18 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
600 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
20 ms |
848 KB |
Output is correct |
11 |
Correct |
19 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
348 KB |
Output is correct |
13 |
Correct |
15 ms |
344 KB |
Output is correct |
14 |
Correct |
16 ms |
608 KB |
Output is correct |
15 |
Correct |
16 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
600 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
348 KB |
Output is correct |
20 |
Correct |
18 ms |
604 KB |
Output is correct |
21 |
Correct |
49 ms |
748 KB |
Output is correct |
22 |
Correct |
56 ms |
828 KB |
Output is correct |
23 |
Correct |
34 ms |
596 KB |
Output is correct |
24 |
Correct |
80 ms |
596 KB |
Output is correct |
25 |
Correct |
79 ms |
596 KB |
Output is correct |
26 |
Correct |
88 ms |
744 KB |
Output is correct |
27 |
Correct |
86 ms |
576 KB |
Output is correct |
28 |
Correct |
86 ms |
592 KB |
Output is correct |
29 |
Correct |
87 ms |
348 KB |
Output is correct |
30 |
Correct |
87 ms |
344 KB |
Output is correct |
31 |
Correct |
87 ms |
600 KB |
Output is correct |
32 |
Correct |
86 ms |
596 KB |
Output is correct |
33 |
Correct |
86 ms |
348 KB |
Output is correct |
34 |
Correct |
87 ms |
344 KB |
Output is correct |
35 |
Correct |
88 ms |
588 KB |
Output is correct |
36 |
Correct |
87 ms |
572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
600 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
20 ms |
848 KB |
Output is correct |
11 |
Correct |
19 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
348 KB |
Output is correct |
13 |
Correct |
15 ms |
344 KB |
Output is correct |
14 |
Correct |
16 ms |
608 KB |
Output is correct |
15 |
Correct |
16 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
600 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
348 KB |
Output is correct |
20 |
Correct |
18 ms |
604 KB |
Output is correct |
21 |
Correct |
49 ms |
748 KB |
Output is correct |
22 |
Correct |
56 ms |
828 KB |
Output is correct |
23 |
Correct |
34 ms |
596 KB |
Output is correct |
24 |
Correct |
80 ms |
596 KB |
Output is correct |
25 |
Correct |
79 ms |
596 KB |
Output is correct |
26 |
Correct |
88 ms |
744 KB |
Output is correct |
27 |
Correct |
86 ms |
576 KB |
Output is correct |
28 |
Correct |
86 ms |
592 KB |
Output is correct |
29 |
Correct |
87 ms |
348 KB |
Output is correct |
30 |
Correct |
87 ms |
344 KB |
Output is correct |
31 |
Correct |
87 ms |
600 KB |
Output is correct |
32 |
Correct |
86 ms |
596 KB |
Output is correct |
33 |
Correct |
86 ms |
348 KB |
Output is correct |
34 |
Correct |
87 ms |
344 KB |
Output is correct |
35 |
Correct |
88 ms |
588 KB |
Output is correct |
36 |
Correct |
87 ms |
572 KB |
Output is correct |
37 |
Correct |
249 ms |
572 KB |
Output is correct |
38 |
Correct |
254 ms |
576 KB |
Output is correct |
39 |
Correct |
363 ms |
348 KB |
Output is correct |
40 |
Correct |
408 ms |
592 KB |
Output is correct |
41 |
Correct |
424 ms |
600 KB |
Output is correct |
42 |
Correct |
359 ms |
572 KB |
Output is correct |
43 |
Correct |
342 ms |
848 KB |
Output is correct |
44 |
Correct |
362 ms |
852 KB |
Output is correct |
45 |
Correct |
395 ms |
852 KB |
Output is correct |
46 |
Correct |
467 ms |
348 KB |
Output is correct |
47 |
Correct |
366 ms |
576 KB |
Output is correct |
48 |
Correct |
368 ms |
844 KB |
Output is correct |
49 |
Correct |
363 ms |
592 KB |
Output is correct |
50 |
Correct |
364 ms |
596 KB |
Output is correct |
51 |
Correct |
1 ms |
600 KB |
Output is correct |
52 |
Correct |
403 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
600 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
20 ms |
848 KB |
Output is correct |
11 |
Correct |
19 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
348 KB |
Output is correct |
13 |
Correct |
15 ms |
344 KB |
Output is correct |
14 |
Correct |
16 ms |
608 KB |
Output is correct |
15 |
Correct |
16 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
600 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
348 KB |
Output is correct |
20 |
Correct |
18 ms |
604 KB |
Output is correct |
21 |
Correct |
49 ms |
748 KB |
Output is correct |
22 |
Correct |
56 ms |
828 KB |
Output is correct |
23 |
Correct |
34 ms |
596 KB |
Output is correct |
24 |
Correct |
80 ms |
596 KB |
Output is correct |
25 |
Correct |
79 ms |
596 KB |
Output is correct |
26 |
Correct |
88 ms |
744 KB |
Output is correct |
27 |
Correct |
86 ms |
576 KB |
Output is correct |
28 |
Correct |
86 ms |
592 KB |
Output is correct |
29 |
Correct |
87 ms |
348 KB |
Output is correct |
30 |
Correct |
87 ms |
344 KB |
Output is correct |
31 |
Correct |
87 ms |
600 KB |
Output is correct |
32 |
Correct |
86 ms |
596 KB |
Output is correct |
33 |
Correct |
86 ms |
348 KB |
Output is correct |
34 |
Correct |
87 ms |
344 KB |
Output is correct |
35 |
Correct |
88 ms |
588 KB |
Output is correct |
36 |
Correct |
87 ms |
572 KB |
Output is correct |
37 |
Correct |
249 ms |
572 KB |
Output is correct |
38 |
Correct |
254 ms |
576 KB |
Output is correct |
39 |
Correct |
363 ms |
348 KB |
Output is correct |
40 |
Correct |
408 ms |
592 KB |
Output is correct |
41 |
Correct |
424 ms |
600 KB |
Output is correct |
42 |
Correct |
359 ms |
572 KB |
Output is correct |
43 |
Correct |
342 ms |
848 KB |
Output is correct |
44 |
Correct |
362 ms |
852 KB |
Output is correct |
45 |
Correct |
395 ms |
852 KB |
Output is correct |
46 |
Correct |
467 ms |
348 KB |
Output is correct |
47 |
Correct |
366 ms |
576 KB |
Output is correct |
48 |
Correct |
368 ms |
844 KB |
Output is correct |
49 |
Correct |
363 ms |
592 KB |
Output is correct |
50 |
Correct |
364 ms |
596 KB |
Output is correct |
51 |
Correct |
1 ms |
600 KB |
Output is correct |
52 |
Correct |
403 ms |
852 KB |
Output is correct |
53 |
Correct |
492 ms |
832 KB |
Output is correct |
54 |
Correct |
648 ms |
832 KB |
Output is correct |
55 |
Correct |
622 ms |
960 KB |
Output is correct |
56 |
Correct |
498 ms |
852 KB |
Output is correct |
57 |
Correct |
623 ms |
1216 KB |
Output is correct |
58 |
Correct |
643 ms |
836 KB |
Output is correct |
59 |
Correct |
641 ms |
980 KB |
Output is correct |
60 |
Correct |
2 ms |
600 KB |
Output is correct |
61 |
Correct |
639 ms |
976 KB |
Output is correct |
62 |
Correct |
540 ms |
1212 KB |
Output is correct |
63 |
Correct |
532 ms |
984 KB |
Output is correct |
64 |
Correct |
524 ms |
984 KB |
Output is correct |
65 |
Correct |
542 ms |
592 KB |
Output is correct |
66 |
Correct |
530 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
600 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
20 ms |
848 KB |
Output is correct |
11 |
Correct |
19 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
348 KB |
Output is correct |
13 |
Correct |
15 ms |
344 KB |
Output is correct |
14 |
Correct |
16 ms |
608 KB |
Output is correct |
15 |
Correct |
16 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
600 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
348 KB |
Output is correct |
20 |
Correct |
18 ms |
604 KB |
Output is correct |
21 |
Correct |
49 ms |
748 KB |
Output is correct |
22 |
Correct |
56 ms |
828 KB |
Output is correct |
23 |
Correct |
34 ms |
596 KB |
Output is correct |
24 |
Correct |
80 ms |
596 KB |
Output is correct |
25 |
Correct |
79 ms |
596 KB |
Output is correct |
26 |
Correct |
88 ms |
744 KB |
Output is correct |
27 |
Correct |
86 ms |
576 KB |
Output is correct |
28 |
Correct |
86 ms |
592 KB |
Output is correct |
29 |
Correct |
87 ms |
348 KB |
Output is correct |
30 |
Correct |
87 ms |
344 KB |
Output is correct |
31 |
Correct |
87 ms |
600 KB |
Output is correct |
32 |
Correct |
86 ms |
596 KB |
Output is correct |
33 |
Correct |
86 ms |
348 KB |
Output is correct |
34 |
Correct |
87 ms |
344 KB |
Output is correct |
35 |
Correct |
88 ms |
588 KB |
Output is correct |
36 |
Correct |
87 ms |
572 KB |
Output is correct |
37 |
Correct |
249 ms |
572 KB |
Output is correct |
38 |
Correct |
254 ms |
576 KB |
Output is correct |
39 |
Correct |
363 ms |
348 KB |
Output is correct |
40 |
Correct |
408 ms |
592 KB |
Output is correct |
41 |
Correct |
424 ms |
600 KB |
Output is correct |
42 |
Correct |
359 ms |
572 KB |
Output is correct |
43 |
Correct |
342 ms |
848 KB |
Output is correct |
44 |
Correct |
362 ms |
852 KB |
Output is correct |
45 |
Correct |
395 ms |
852 KB |
Output is correct |
46 |
Correct |
467 ms |
348 KB |
Output is correct |
47 |
Correct |
366 ms |
576 KB |
Output is correct |
48 |
Correct |
368 ms |
844 KB |
Output is correct |
49 |
Correct |
363 ms |
592 KB |
Output is correct |
50 |
Correct |
364 ms |
596 KB |
Output is correct |
51 |
Correct |
1 ms |
600 KB |
Output is correct |
52 |
Correct |
403 ms |
852 KB |
Output is correct |
53 |
Correct |
492 ms |
832 KB |
Output is correct |
54 |
Correct |
648 ms |
832 KB |
Output is correct |
55 |
Correct |
622 ms |
960 KB |
Output is correct |
56 |
Correct |
498 ms |
852 KB |
Output is correct |
57 |
Correct |
623 ms |
1216 KB |
Output is correct |
58 |
Correct |
643 ms |
836 KB |
Output is correct |
59 |
Correct |
641 ms |
980 KB |
Output is correct |
60 |
Correct |
2 ms |
600 KB |
Output is correct |
61 |
Correct |
639 ms |
976 KB |
Output is correct |
62 |
Correct |
540 ms |
1212 KB |
Output is correct |
63 |
Correct |
532 ms |
984 KB |
Output is correct |
64 |
Correct |
524 ms |
984 KB |
Output is correct |
65 |
Correct |
542 ms |
592 KB |
Output is correct |
66 |
Correct |
530 ms |
596 KB |
Output is correct |
67 |
Correct |
801 ms |
984 KB |
Output is correct |
68 |
Correct |
2 ms |
604 KB |
Output is correct |
69 |
Execution timed out |
1096 ms |
544 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |