#include "bits/stdc++.h"
using namespace std;
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n;
vector <int> a(n + 1, 0);
int sm = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sm += a[i];
}
if (sm % 2) return cout << 0, 0;
int m = (sm + 4000)>>1;
vector <int> dp(m + 1, 0);
dp[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = m - a[i]; j >= 0; j--) dp[j + a[i]] += dp[j];
}
if (!dp[sm>>1]) return cout << 0, 0;
vector <int> ans;
int x = 0;
while (++x <= 4000) {
int smv = sm + x;
int mv = smv>>1;
vector <int> v = a; v.push_back(x);
vector <int> can = dp;
for (int i = mv; i >= x; i--) can[i] += can[i - x];
bool tr = true;
for (int i = 1; i <= n + 1; i++) {
if ((smv - v[i]) % 2) {
tr = false;
break;
}
for (int j = v[i]; j <= mv; j++) can[j] -= can[j - v[i]];
if (!can[(smv - v[i])>>1]) {
tr = false;
break;
}
for (int j = mv; j >= v[i]; j--) can[j] += can[j - v[i]];
}
if (tr) ans.push_back(x);
}
cout << (int)ans.size() << '\n';
for (auto i : ans) cout << i << ' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
8 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
10 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
8 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
10 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Correct |
7 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
212 KB |
Output is correct |
13 |
Correct |
4 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
212 KB |
Output is correct |
15 |
Correct |
5 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
5 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
248 KB |
Output is correct |
20 |
Correct |
5 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
8 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
10 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Correct |
7 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
212 KB |
Output is correct |
13 |
Correct |
4 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
212 KB |
Output is correct |
15 |
Correct |
5 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
5 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
248 KB |
Output is correct |
20 |
Correct |
5 ms |
336 KB |
Output is correct |
21 |
Correct |
372 ms |
348 KB |
Output is correct |
22 |
Correct |
519 ms |
464 KB |
Output is correct |
23 |
Correct |
164 ms |
340 KB |
Output is correct |
24 |
Incorrect |
975 ms |
340 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
8 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
10 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Correct |
7 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
212 KB |
Output is correct |
13 |
Correct |
4 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
212 KB |
Output is correct |
15 |
Correct |
5 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
5 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
248 KB |
Output is correct |
20 |
Correct |
5 ms |
336 KB |
Output is correct |
21 |
Correct |
372 ms |
348 KB |
Output is correct |
22 |
Correct |
519 ms |
464 KB |
Output is correct |
23 |
Correct |
164 ms |
340 KB |
Output is correct |
24 |
Incorrect |
975 ms |
340 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
8 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
10 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Correct |
7 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
212 KB |
Output is correct |
13 |
Correct |
4 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
212 KB |
Output is correct |
15 |
Correct |
5 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
5 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
248 KB |
Output is correct |
20 |
Correct |
5 ms |
336 KB |
Output is correct |
21 |
Correct |
372 ms |
348 KB |
Output is correct |
22 |
Correct |
519 ms |
464 KB |
Output is correct |
23 |
Correct |
164 ms |
340 KB |
Output is correct |
24 |
Incorrect |
975 ms |
340 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
8 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
10 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Correct |
7 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
212 KB |
Output is correct |
13 |
Correct |
4 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
212 KB |
Output is correct |
15 |
Correct |
5 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
5 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
248 KB |
Output is correct |
20 |
Correct |
5 ms |
336 KB |
Output is correct |
21 |
Correct |
372 ms |
348 KB |
Output is correct |
22 |
Correct |
519 ms |
464 KB |
Output is correct |
23 |
Correct |
164 ms |
340 KB |
Output is correct |
24 |
Incorrect |
975 ms |
340 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |