#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;
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 |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
5 |
Correct |
8 ms |
604 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
8 ms |
600 KB |
Output is correct |
9 |
Correct |
7 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
5 |
Correct |
8 ms |
604 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
8 ms |
600 KB |
Output is correct |
9 |
Correct |
7 ms |
600 KB |
Output is correct |
10 |
Correct |
20 ms |
344 KB |
Output is correct |
11 |
Correct |
20 ms |
604 KB |
Output is correct |
12 |
Correct |
20 ms |
344 KB |
Output is correct |
13 |
Correct |
17 ms |
348 KB |
Output is correct |
14 |
Correct |
19 ms |
604 KB |
Output is correct |
15 |
Correct |
18 ms |
348 KB |
Output is correct |
16 |
Correct |
20 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
604 KB |
Output is correct |
18 |
Correct |
15 ms |
604 KB |
Output is correct |
19 |
Correct |
17 ms |
604 KB |
Output is correct |
20 |
Correct |
20 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
5 |
Correct |
8 ms |
604 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
8 ms |
600 KB |
Output is correct |
9 |
Correct |
7 ms |
600 KB |
Output is correct |
10 |
Correct |
20 ms |
344 KB |
Output is correct |
11 |
Correct |
20 ms |
604 KB |
Output is correct |
12 |
Correct |
20 ms |
344 KB |
Output is correct |
13 |
Correct |
17 ms |
348 KB |
Output is correct |
14 |
Correct |
19 ms |
604 KB |
Output is correct |
15 |
Correct |
18 ms |
348 KB |
Output is correct |
16 |
Correct |
20 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
604 KB |
Output is correct |
18 |
Correct |
15 ms |
604 KB |
Output is correct |
19 |
Correct |
17 ms |
604 KB |
Output is correct |
20 |
Correct |
20 ms |
348 KB |
Output is correct |
21 |
Correct |
53 ms |
584 KB |
Output is correct |
22 |
Correct |
77 ms |
600 KB |
Output is correct |
23 |
Correct |
38 ms |
604 KB |
Output is correct |
24 |
Correct |
93 ms |
596 KB |
Output is correct |
25 |
Correct |
93 ms |
580 KB |
Output is correct |
26 |
Correct |
104 ms |
604 KB |
Output is correct |
27 |
Correct |
111 ms |
604 KB |
Output is correct |
28 |
Correct |
106 ms |
604 KB |
Output is correct |
29 |
Correct |
105 ms |
604 KB |
Output is correct |
30 |
Correct |
102 ms |
348 KB |
Output is correct |
31 |
Correct |
102 ms |
580 KB |
Output is correct |
32 |
Correct |
103 ms |
600 KB |
Output is correct |
33 |
Correct |
102 ms |
348 KB |
Output is correct |
34 |
Correct |
108 ms |
604 KB |
Output is correct |
35 |
Correct |
102 ms |
580 KB |
Output is correct |
36 |
Correct |
102 ms |
580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
5 |
Correct |
8 ms |
604 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
8 ms |
600 KB |
Output is correct |
9 |
Correct |
7 ms |
600 KB |
Output is correct |
10 |
Correct |
20 ms |
344 KB |
Output is correct |
11 |
Correct |
20 ms |
604 KB |
Output is correct |
12 |
Correct |
20 ms |
344 KB |
Output is correct |
13 |
Correct |
17 ms |
348 KB |
Output is correct |
14 |
Correct |
19 ms |
604 KB |
Output is correct |
15 |
Correct |
18 ms |
348 KB |
Output is correct |
16 |
Correct |
20 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
604 KB |
Output is correct |
18 |
Correct |
15 ms |
604 KB |
Output is correct |
19 |
Correct |
17 ms |
604 KB |
Output is correct |
20 |
Correct |
20 ms |
348 KB |
Output is correct |
21 |
Correct |
53 ms |
584 KB |
Output is correct |
22 |
Correct |
77 ms |
600 KB |
Output is correct |
23 |
Correct |
38 ms |
604 KB |
Output is correct |
24 |
Correct |
93 ms |
596 KB |
Output is correct |
25 |
Correct |
93 ms |
580 KB |
Output is correct |
26 |
Correct |
104 ms |
604 KB |
Output is correct |
27 |
Correct |
111 ms |
604 KB |
Output is correct |
28 |
Correct |
106 ms |
604 KB |
Output is correct |
29 |
Correct |
105 ms |
604 KB |
Output is correct |
30 |
Correct |
102 ms |
348 KB |
Output is correct |
31 |
Correct |
102 ms |
580 KB |
Output is correct |
32 |
Correct |
103 ms |
600 KB |
Output is correct |
33 |
Correct |
102 ms |
348 KB |
Output is correct |
34 |
Correct |
108 ms |
604 KB |
Output is correct |
35 |
Correct |
102 ms |
580 KB |
Output is correct |
36 |
Correct |
102 ms |
580 KB |
Output is correct |
37 |
Correct |
320 ms |
600 KB |
Output is correct |
38 |
Correct |
320 ms |
604 KB |
Output is correct |
39 |
Correct |
463 ms |
580 KB |
Output is correct |
40 |
Correct |
547 ms |
588 KB |
Output is correct |
41 |
Correct |
543 ms |
348 KB |
Output is correct |
42 |
Correct |
471 ms |
604 KB |
Output is correct |
43 |
Correct |
483 ms |
836 KB |
Output is correct |
44 |
Correct |
471 ms |
824 KB |
Output is correct |
45 |
Correct |
485 ms |
852 KB |
Output is correct |
46 |
Correct |
551 ms |
348 KB |
Output is correct |
47 |
Correct |
458 ms |
580 KB |
Output is correct |
48 |
Correct |
468 ms |
844 KB |
Output is correct |
49 |
Correct |
463 ms |
544 KB |
Output is correct |
50 |
Correct |
469 ms |
580 KB |
Output is correct |
51 |
Correct |
3 ms |
600 KB |
Output is correct |
52 |
Correct |
528 ms |
836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
5 |
Correct |
8 ms |
604 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
8 ms |
600 KB |
Output is correct |
9 |
Correct |
7 ms |
600 KB |
Output is correct |
10 |
Correct |
20 ms |
344 KB |
Output is correct |
11 |
Correct |
20 ms |
604 KB |
Output is correct |
12 |
Correct |
20 ms |
344 KB |
Output is correct |
13 |
Correct |
17 ms |
348 KB |
Output is correct |
14 |
Correct |
19 ms |
604 KB |
Output is correct |
15 |
Correct |
18 ms |
348 KB |
Output is correct |
16 |
Correct |
20 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
604 KB |
Output is correct |
18 |
Correct |
15 ms |
604 KB |
Output is correct |
19 |
Correct |
17 ms |
604 KB |
Output is correct |
20 |
Correct |
20 ms |
348 KB |
Output is correct |
21 |
Correct |
53 ms |
584 KB |
Output is correct |
22 |
Correct |
77 ms |
600 KB |
Output is correct |
23 |
Correct |
38 ms |
604 KB |
Output is correct |
24 |
Correct |
93 ms |
596 KB |
Output is correct |
25 |
Correct |
93 ms |
580 KB |
Output is correct |
26 |
Correct |
104 ms |
604 KB |
Output is correct |
27 |
Correct |
111 ms |
604 KB |
Output is correct |
28 |
Correct |
106 ms |
604 KB |
Output is correct |
29 |
Correct |
105 ms |
604 KB |
Output is correct |
30 |
Correct |
102 ms |
348 KB |
Output is correct |
31 |
Correct |
102 ms |
580 KB |
Output is correct |
32 |
Correct |
103 ms |
600 KB |
Output is correct |
33 |
Correct |
102 ms |
348 KB |
Output is correct |
34 |
Correct |
108 ms |
604 KB |
Output is correct |
35 |
Correct |
102 ms |
580 KB |
Output is correct |
36 |
Correct |
102 ms |
580 KB |
Output is correct |
37 |
Correct |
320 ms |
600 KB |
Output is correct |
38 |
Correct |
320 ms |
604 KB |
Output is correct |
39 |
Correct |
463 ms |
580 KB |
Output is correct |
40 |
Correct |
547 ms |
588 KB |
Output is correct |
41 |
Correct |
543 ms |
348 KB |
Output is correct |
42 |
Correct |
471 ms |
604 KB |
Output is correct |
43 |
Correct |
483 ms |
836 KB |
Output is correct |
44 |
Correct |
471 ms |
824 KB |
Output is correct |
45 |
Correct |
485 ms |
852 KB |
Output is correct |
46 |
Correct |
551 ms |
348 KB |
Output is correct |
47 |
Correct |
458 ms |
580 KB |
Output is correct |
48 |
Correct |
468 ms |
844 KB |
Output is correct |
49 |
Correct |
463 ms |
544 KB |
Output is correct |
50 |
Correct |
469 ms |
580 KB |
Output is correct |
51 |
Correct |
3 ms |
600 KB |
Output is correct |
52 |
Correct |
528 ms |
836 KB |
Output is correct |
53 |
Correct |
636 ms |
836 KB |
Output is correct |
54 |
Correct |
834 ms |
1108 KB |
Output is correct |
55 |
Correct |
884 ms |
968 KB |
Output is correct |
56 |
Correct |
668 ms |
852 KB |
Output is correct |
57 |
Correct |
824 ms |
1240 KB |
Output is correct |
58 |
Correct |
828 ms |
840 KB |
Output is correct |
59 |
Correct |
844 ms |
968 KB |
Output is correct |
60 |
Correct |
3 ms |
604 KB |
Output is correct |
61 |
Correct |
892 ms |
968 KB |
Output is correct |
62 |
Correct |
708 ms |
972 KB |
Output is correct |
63 |
Correct |
744 ms |
984 KB |
Output is correct |
64 |
Correct |
694 ms |
968 KB |
Output is correct |
65 |
Correct |
715 ms |
576 KB |
Output is correct |
66 |
Correct |
728 ms |
580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
5 |
Correct |
8 ms |
604 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
8 ms |
600 KB |
Output is correct |
9 |
Correct |
7 ms |
600 KB |
Output is correct |
10 |
Correct |
20 ms |
344 KB |
Output is correct |
11 |
Correct |
20 ms |
604 KB |
Output is correct |
12 |
Correct |
20 ms |
344 KB |
Output is correct |
13 |
Correct |
17 ms |
348 KB |
Output is correct |
14 |
Correct |
19 ms |
604 KB |
Output is correct |
15 |
Correct |
18 ms |
348 KB |
Output is correct |
16 |
Correct |
20 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
604 KB |
Output is correct |
18 |
Correct |
15 ms |
604 KB |
Output is correct |
19 |
Correct |
17 ms |
604 KB |
Output is correct |
20 |
Correct |
20 ms |
348 KB |
Output is correct |
21 |
Correct |
53 ms |
584 KB |
Output is correct |
22 |
Correct |
77 ms |
600 KB |
Output is correct |
23 |
Correct |
38 ms |
604 KB |
Output is correct |
24 |
Correct |
93 ms |
596 KB |
Output is correct |
25 |
Correct |
93 ms |
580 KB |
Output is correct |
26 |
Correct |
104 ms |
604 KB |
Output is correct |
27 |
Correct |
111 ms |
604 KB |
Output is correct |
28 |
Correct |
106 ms |
604 KB |
Output is correct |
29 |
Correct |
105 ms |
604 KB |
Output is correct |
30 |
Correct |
102 ms |
348 KB |
Output is correct |
31 |
Correct |
102 ms |
580 KB |
Output is correct |
32 |
Correct |
103 ms |
600 KB |
Output is correct |
33 |
Correct |
102 ms |
348 KB |
Output is correct |
34 |
Correct |
108 ms |
604 KB |
Output is correct |
35 |
Correct |
102 ms |
580 KB |
Output is correct |
36 |
Correct |
102 ms |
580 KB |
Output is correct |
37 |
Correct |
320 ms |
600 KB |
Output is correct |
38 |
Correct |
320 ms |
604 KB |
Output is correct |
39 |
Correct |
463 ms |
580 KB |
Output is correct |
40 |
Correct |
547 ms |
588 KB |
Output is correct |
41 |
Correct |
543 ms |
348 KB |
Output is correct |
42 |
Correct |
471 ms |
604 KB |
Output is correct |
43 |
Correct |
483 ms |
836 KB |
Output is correct |
44 |
Correct |
471 ms |
824 KB |
Output is correct |
45 |
Correct |
485 ms |
852 KB |
Output is correct |
46 |
Correct |
551 ms |
348 KB |
Output is correct |
47 |
Correct |
458 ms |
580 KB |
Output is correct |
48 |
Correct |
468 ms |
844 KB |
Output is correct |
49 |
Correct |
463 ms |
544 KB |
Output is correct |
50 |
Correct |
469 ms |
580 KB |
Output is correct |
51 |
Correct |
3 ms |
600 KB |
Output is correct |
52 |
Correct |
528 ms |
836 KB |
Output is correct |
53 |
Correct |
636 ms |
836 KB |
Output is correct |
54 |
Correct |
834 ms |
1108 KB |
Output is correct |
55 |
Correct |
884 ms |
968 KB |
Output is correct |
56 |
Correct |
668 ms |
852 KB |
Output is correct |
57 |
Correct |
824 ms |
1240 KB |
Output is correct |
58 |
Correct |
828 ms |
840 KB |
Output is correct |
59 |
Correct |
844 ms |
968 KB |
Output is correct |
60 |
Correct |
3 ms |
604 KB |
Output is correct |
61 |
Correct |
892 ms |
968 KB |
Output is correct |
62 |
Correct |
708 ms |
972 KB |
Output is correct |
63 |
Correct |
744 ms |
984 KB |
Output is correct |
64 |
Correct |
694 ms |
968 KB |
Output is correct |
65 |
Correct |
715 ms |
576 KB |
Output is correct |
66 |
Correct |
728 ms |
580 KB |
Output is correct |
67 |
Execution timed out |
1065 ms |
544 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |