#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")
#pragma GCC optimize("unroll-loops")
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])) { */
if (newsum % 2 || newsum/2 < x || !pos[newsum/2]) {
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 |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
608 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
608 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
18 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
348 KB |
Output is correct |
13 |
Correct |
16 ms |
600 KB |
Output is correct |
14 |
Correct |
16 ms |
344 KB |
Output is correct |
15 |
Correct |
16 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
10 ms |
604 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
604 KB |
Output is correct |
20 |
Correct |
18 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
608 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
18 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
348 KB |
Output is correct |
13 |
Correct |
16 ms |
600 KB |
Output is correct |
14 |
Correct |
16 ms |
344 KB |
Output is correct |
15 |
Correct |
16 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
10 ms |
604 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
604 KB |
Output is correct |
20 |
Correct |
18 ms |
348 KB |
Output is correct |
21 |
Correct |
45 ms |
588 KB |
Output is correct |
22 |
Correct |
56 ms |
572 KB |
Output is correct |
23 |
Correct |
33 ms |
592 KB |
Output is correct |
24 |
Correct |
77 ms |
596 KB |
Output is correct |
25 |
Correct |
78 ms |
596 KB |
Output is correct |
26 |
Correct |
85 ms |
576 KB |
Output is correct |
27 |
Correct |
85 ms |
596 KB |
Output is correct |
28 |
Correct |
87 ms |
592 KB |
Output is correct |
29 |
Correct |
85 ms |
348 KB |
Output is correct |
30 |
Correct |
85 ms |
576 KB |
Output is correct |
31 |
Correct |
86 ms |
592 KB |
Output is correct |
32 |
Correct |
85 ms |
576 KB |
Output is correct |
33 |
Correct |
90 ms |
576 KB |
Output is correct |
34 |
Correct |
84 ms |
344 KB |
Output is correct |
35 |
Correct |
86 ms |
348 KB |
Output is correct |
36 |
Correct |
85 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
608 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
18 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
348 KB |
Output is correct |
13 |
Correct |
16 ms |
600 KB |
Output is correct |
14 |
Correct |
16 ms |
344 KB |
Output is correct |
15 |
Correct |
16 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
10 ms |
604 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
604 KB |
Output is correct |
20 |
Correct |
18 ms |
348 KB |
Output is correct |
21 |
Correct |
45 ms |
588 KB |
Output is correct |
22 |
Correct |
56 ms |
572 KB |
Output is correct |
23 |
Correct |
33 ms |
592 KB |
Output is correct |
24 |
Correct |
77 ms |
596 KB |
Output is correct |
25 |
Correct |
78 ms |
596 KB |
Output is correct |
26 |
Correct |
85 ms |
576 KB |
Output is correct |
27 |
Correct |
85 ms |
596 KB |
Output is correct |
28 |
Correct |
87 ms |
592 KB |
Output is correct |
29 |
Correct |
85 ms |
348 KB |
Output is correct |
30 |
Correct |
85 ms |
576 KB |
Output is correct |
31 |
Correct |
86 ms |
592 KB |
Output is correct |
32 |
Correct |
85 ms |
576 KB |
Output is correct |
33 |
Correct |
90 ms |
576 KB |
Output is correct |
34 |
Correct |
84 ms |
344 KB |
Output is correct |
35 |
Correct |
86 ms |
348 KB |
Output is correct |
36 |
Correct |
85 ms |
596 KB |
Output is correct |
37 |
Correct |
250 ms |
596 KB |
Output is correct |
38 |
Correct |
246 ms |
576 KB |
Output is correct |
39 |
Correct |
358 ms |
344 KB |
Output is correct |
40 |
Correct |
404 ms |
580 KB |
Output is correct |
41 |
Correct |
418 ms |
596 KB |
Output is correct |
42 |
Correct |
356 ms |
600 KB |
Output is correct |
43 |
Correct |
337 ms |
852 KB |
Output is correct |
44 |
Correct |
348 ms |
848 KB |
Output is correct |
45 |
Correct |
351 ms |
828 KB |
Output is correct |
46 |
Correct |
406 ms |
344 KB |
Output is correct |
47 |
Correct |
359 ms |
572 KB |
Output is correct |
48 |
Correct |
352 ms |
828 KB |
Output is correct |
49 |
Correct |
361 ms |
576 KB |
Output is correct |
50 |
Correct |
354 ms |
596 KB |
Output is correct |
51 |
Correct |
1 ms |
344 KB |
Output is correct |
52 |
Correct |
404 ms |
836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
608 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
18 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
348 KB |
Output is correct |
13 |
Correct |
16 ms |
600 KB |
Output is correct |
14 |
Correct |
16 ms |
344 KB |
Output is correct |
15 |
Correct |
16 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
10 ms |
604 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
604 KB |
Output is correct |
20 |
Correct |
18 ms |
348 KB |
Output is correct |
21 |
Correct |
45 ms |
588 KB |
Output is correct |
22 |
Correct |
56 ms |
572 KB |
Output is correct |
23 |
Correct |
33 ms |
592 KB |
Output is correct |
24 |
Correct |
77 ms |
596 KB |
Output is correct |
25 |
Correct |
78 ms |
596 KB |
Output is correct |
26 |
Correct |
85 ms |
576 KB |
Output is correct |
27 |
Correct |
85 ms |
596 KB |
Output is correct |
28 |
Correct |
87 ms |
592 KB |
Output is correct |
29 |
Correct |
85 ms |
348 KB |
Output is correct |
30 |
Correct |
85 ms |
576 KB |
Output is correct |
31 |
Correct |
86 ms |
592 KB |
Output is correct |
32 |
Correct |
85 ms |
576 KB |
Output is correct |
33 |
Correct |
90 ms |
576 KB |
Output is correct |
34 |
Correct |
84 ms |
344 KB |
Output is correct |
35 |
Correct |
86 ms |
348 KB |
Output is correct |
36 |
Correct |
85 ms |
596 KB |
Output is correct |
37 |
Correct |
250 ms |
596 KB |
Output is correct |
38 |
Correct |
246 ms |
576 KB |
Output is correct |
39 |
Correct |
358 ms |
344 KB |
Output is correct |
40 |
Correct |
404 ms |
580 KB |
Output is correct |
41 |
Correct |
418 ms |
596 KB |
Output is correct |
42 |
Correct |
356 ms |
600 KB |
Output is correct |
43 |
Correct |
337 ms |
852 KB |
Output is correct |
44 |
Correct |
348 ms |
848 KB |
Output is correct |
45 |
Correct |
351 ms |
828 KB |
Output is correct |
46 |
Correct |
406 ms |
344 KB |
Output is correct |
47 |
Correct |
359 ms |
572 KB |
Output is correct |
48 |
Correct |
352 ms |
828 KB |
Output is correct |
49 |
Correct |
361 ms |
576 KB |
Output is correct |
50 |
Correct |
354 ms |
596 KB |
Output is correct |
51 |
Correct |
1 ms |
344 KB |
Output is correct |
52 |
Correct |
404 ms |
836 KB |
Output is correct |
53 |
Correct |
484 ms |
828 KB |
Output is correct |
54 |
Correct |
630 ms |
852 KB |
Output is correct |
55 |
Correct |
617 ms |
984 KB |
Output is correct |
56 |
Correct |
498 ms |
848 KB |
Output is correct |
57 |
Correct |
614 ms |
1240 KB |
Output is correct |
58 |
Correct |
634 ms |
836 KB |
Output is correct |
59 |
Correct |
636 ms |
964 KB |
Output is correct |
60 |
Correct |
2 ms |
348 KB |
Output is correct |
61 |
Correct |
627 ms |
976 KB |
Output is correct |
62 |
Correct |
526 ms |
980 KB |
Output is correct |
63 |
Correct |
532 ms |
964 KB |
Output is correct |
64 |
Correct |
512 ms |
984 KB |
Output is correct |
65 |
Correct |
539 ms |
596 KB |
Output is correct |
66 |
Correct |
524 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
608 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
18 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
348 KB |
Output is correct |
13 |
Correct |
16 ms |
600 KB |
Output is correct |
14 |
Correct |
16 ms |
344 KB |
Output is correct |
15 |
Correct |
16 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
348 KB |
Output is correct |
17 |
Correct |
10 ms |
604 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
604 KB |
Output is correct |
20 |
Correct |
18 ms |
348 KB |
Output is correct |
21 |
Correct |
45 ms |
588 KB |
Output is correct |
22 |
Correct |
56 ms |
572 KB |
Output is correct |
23 |
Correct |
33 ms |
592 KB |
Output is correct |
24 |
Correct |
77 ms |
596 KB |
Output is correct |
25 |
Correct |
78 ms |
596 KB |
Output is correct |
26 |
Correct |
85 ms |
576 KB |
Output is correct |
27 |
Correct |
85 ms |
596 KB |
Output is correct |
28 |
Correct |
87 ms |
592 KB |
Output is correct |
29 |
Correct |
85 ms |
348 KB |
Output is correct |
30 |
Correct |
85 ms |
576 KB |
Output is correct |
31 |
Correct |
86 ms |
592 KB |
Output is correct |
32 |
Correct |
85 ms |
576 KB |
Output is correct |
33 |
Correct |
90 ms |
576 KB |
Output is correct |
34 |
Correct |
84 ms |
344 KB |
Output is correct |
35 |
Correct |
86 ms |
348 KB |
Output is correct |
36 |
Correct |
85 ms |
596 KB |
Output is correct |
37 |
Correct |
250 ms |
596 KB |
Output is correct |
38 |
Correct |
246 ms |
576 KB |
Output is correct |
39 |
Correct |
358 ms |
344 KB |
Output is correct |
40 |
Correct |
404 ms |
580 KB |
Output is correct |
41 |
Correct |
418 ms |
596 KB |
Output is correct |
42 |
Correct |
356 ms |
600 KB |
Output is correct |
43 |
Correct |
337 ms |
852 KB |
Output is correct |
44 |
Correct |
348 ms |
848 KB |
Output is correct |
45 |
Correct |
351 ms |
828 KB |
Output is correct |
46 |
Correct |
406 ms |
344 KB |
Output is correct |
47 |
Correct |
359 ms |
572 KB |
Output is correct |
48 |
Correct |
352 ms |
828 KB |
Output is correct |
49 |
Correct |
361 ms |
576 KB |
Output is correct |
50 |
Correct |
354 ms |
596 KB |
Output is correct |
51 |
Correct |
1 ms |
344 KB |
Output is correct |
52 |
Correct |
404 ms |
836 KB |
Output is correct |
53 |
Correct |
484 ms |
828 KB |
Output is correct |
54 |
Correct |
630 ms |
852 KB |
Output is correct |
55 |
Correct |
617 ms |
984 KB |
Output is correct |
56 |
Correct |
498 ms |
848 KB |
Output is correct |
57 |
Correct |
614 ms |
1240 KB |
Output is correct |
58 |
Correct |
634 ms |
836 KB |
Output is correct |
59 |
Correct |
636 ms |
964 KB |
Output is correct |
60 |
Correct |
2 ms |
348 KB |
Output is correct |
61 |
Correct |
627 ms |
976 KB |
Output is correct |
62 |
Correct |
526 ms |
980 KB |
Output is correct |
63 |
Correct |
532 ms |
964 KB |
Output is correct |
64 |
Correct |
512 ms |
984 KB |
Output is correct |
65 |
Correct |
539 ms |
596 KB |
Output is correct |
66 |
Correct |
524 ms |
596 KB |
Output is correct |
67 |
Correct |
793 ms |
980 KB |
Output is correct |
68 |
Correct |
2 ms |
344 KB |
Output is correct |
69 |
Execution timed out |
1058 ms |
348 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |