#include <bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
int a[n+1], suma = 0;
for (int i = 1; i <= n; ++i){
cin >> a[i];
suma += a[i];
}
vi s(suma+10, INT32_MAX);
s[0] = 0;
for (int i = 1; i <= n; ++i){
for (int j = 0; j <= suma; ++j){
if (s[j] < i){
s[a[i]+j] = min(s[a[i]+j], i);
}
}
}
if (suma%2 || s[suma/2] == INT32_MAX)
return cout << "0\n", 0;
vi sol(suma+10, 1), moze(suma+10);
for (int k = 1; k <= n; ++k){
fill(s.begin(), s.end(), INT32_MAX);
fill(moze.begin(), moze.end(), 0);
s[0] = 0;
for (int i = 1; i <= n; ++i){
if (i == k) continue;
for (int j = 0; j <= suma; ++j){
if (s[j] < i){
int y = suma - a[k] - 2 * j;
if (y > 0)
moze[y] = 1;
s[a[i]+j] = min(s[a[i]+j], i);
int x = suma - a[k] - 2 * (a[i] + j);
if (x > 0)
moze[x]=1;
}
}
}
for (int i = 1; i < suma; ++i){
if (!moze[i] || !sol[i])
sol[i ] = 0;
}
}
vi res;
for (int i = 1; i < suma; ++i)
if (sol[i])
res.push_back(i);
cout << (int)res.size() << '\n';
for (auto& i : res)
cout << i << ' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
69 ms |
492 KB |
Output is correct |
22 |
Correct |
105 ms |
492 KB |
Output is correct |
23 |
Correct |
31 ms |
492 KB |
Output is correct |
24 |
Correct |
215 ms |
620 KB |
Output is correct |
25 |
Correct |
294 ms |
648 KB |
Output is correct |
26 |
Correct |
355 ms |
620 KB |
Output is correct |
27 |
Correct |
262 ms |
620 KB |
Output is correct |
28 |
Correct |
242 ms |
620 KB |
Output is correct |
29 |
Correct |
266 ms |
620 KB |
Output is correct |
30 |
Correct |
285 ms |
492 KB |
Output is correct |
31 |
Correct |
381 ms |
620 KB |
Output is correct |
32 |
Correct |
258 ms |
492 KB |
Output is correct |
33 |
Correct |
161 ms |
620 KB |
Output is correct |
34 |
Correct |
166 ms |
628 KB |
Output is correct |
35 |
Correct |
248 ms |
620 KB |
Output is correct |
36 |
Correct |
250 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
69 ms |
492 KB |
Output is correct |
22 |
Correct |
105 ms |
492 KB |
Output is correct |
23 |
Correct |
31 ms |
492 KB |
Output is correct |
24 |
Correct |
215 ms |
620 KB |
Output is correct |
25 |
Correct |
294 ms |
648 KB |
Output is correct |
26 |
Correct |
355 ms |
620 KB |
Output is correct |
27 |
Correct |
262 ms |
620 KB |
Output is correct |
28 |
Correct |
242 ms |
620 KB |
Output is correct |
29 |
Correct |
266 ms |
620 KB |
Output is correct |
30 |
Correct |
285 ms |
492 KB |
Output is correct |
31 |
Correct |
381 ms |
620 KB |
Output is correct |
32 |
Correct |
258 ms |
492 KB |
Output is correct |
33 |
Correct |
161 ms |
620 KB |
Output is correct |
34 |
Correct |
166 ms |
628 KB |
Output is correct |
35 |
Correct |
248 ms |
620 KB |
Output is correct |
36 |
Correct |
250 ms |
620 KB |
Output is correct |
37 |
Execution timed out |
1088 ms |
748 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
69 ms |
492 KB |
Output is correct |
22 |
Correct |
105 ms |
492 KB |
Output is correct |
23 |
Correct |
31 ms |
492 KB |
Output is correct |
24 |
Correct |
215 ms |
620 KB |
Output is correct |
25 |
Correct |
294 ms |
648 KB |
Output is correct |
26 |
Correct |
355 ms |
620 KB |
Output is correct |
27 |
Correct |
262 ms |
620 KB |
Output is correct |
28 |
Correct |
242 ms |
620 KB |
Output is correct |
29 |
Correct |
266 ms |
620 KB |
Output is correct |
30 |
Correct |
285 ms |
492 KB |
Output is correct |
31 |
Correct |
381 ms |
620 KB |
Output is correct |
32 |
Correct |
258 ms |
492 KB |
Output is correct |
33 |
Correct |
161 ms |
620 KB |
Output is correct |
34 |
Correct |
166 ms |
628 KB |
Output is correct |
35 |
Correct |
248 ms |
620 KB |
Output is correct |
36 |
Correct |
250 ms |
620 KB |
Output is correct |
37 |
Execution timed out |
1088 ms |
748 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
69 ms |
492 KB |
Output is correct |
22 |
Correct |
105 ms |
492 KB |
Output is correct |
23 |
Correct |
31 ms |
492 KB |
Output is correct |
24 |
Correct |
215 ms |
620 KB |
Output is correct |
25 |
Correct |
294 ms |
648 KB |
Output is correct |
26 |
Correct |
355 ms |
620 KB |
Output is correct |
27 |
Correct |
262 ms |
620 KB |
Output is correct |
28 |
Correct |
242 ms |
620 KB |
Output is correct |
29 |
Correct |
266 ms |
620 KB |
Output is correct |
30 |
Correct |
285 ms |
492 KB |
Output is correct |
31 |
Correct |
381 ms |
620 KB |
Output is correct |
32 |
Correct |
258 ms |
492 KB |
Output is correct |
33 |
Correct |
161 ms |
620 KB |
Output is correct |
34 |
Correct |
166 ms |
628 KB |
Output is correct |
35 |
Correct |
248 ms |
620 KB |
Output is correct |
36 |
Correct |
250 ms |
620 KB |
Output is correct |
37 |
Execution timed out |
1088 ms |
748 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |