#include <bits/stdc++.h>
using namespace std;
/*
written on phone :)))))
*/
const int N = 505;
long long dp[N*N];
int ans[N*N];
void add (int x) {
for (int i = N*N-x-1; i >= 0; i--) {
dp[i+x] += dp[i];
}
}
void del (int x) {
for (int i = x; i < N*N; i++) {
dp[i] -= dp[i-x];
}
}
int main ()
{
dp[0] = 1;
int n; cin >> n;
vector <int> a (n);
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
add(a[i]);
}
if (sum & 1) {
cout << 0; return 0;
}
if (!dp[sum >> 1]) {
cout << 0; return 0;
}
int cnt = 0;
for (int i = 0; i < n; i++) {
del(a[i]); sum-=a[i];
for (int j = 1; j < N*N; j++) {
int need = ((sum+j)>>1)-j;
if (need >= 0 && dp[need] > 0 && (sum+j) % 2 == 0) {
ans[j]++;
}
}
add(a[i]); sum+=a[i];
}
for (int i = 1; i < N*N;i++) {
if (ans[i] == n)
cnt++;
}
cout << cnt << endl;
for (int i = 1; i < N*N;i++) {
if (ans[i] == n)
cout << i << " ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
5 ms |
2252 KB |
Output is correct |
5 |
Correct |
12 ms |
2296 KB |
Output is correct |
6 |
Correct |
8 ms |
2252 KB |
Output is correct |
7 |
Correct |
8 ms |
2288 KB |
Output is correct |
8 |
Correct |
12 ms |
2252 KB |
Output is correct |
9 |
Correct |
11 ms |
2292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
5 ms |
2252 KB |
Output is correct |
5 |
Correct |
12 ms |
2296 KB |
Output is correct |
6 |
Correct |
8 ms |
2252 KB |
Output is correct |
7 |
Correct |
8 ms |
2288 KB |
Output is correct |
8 |
Correct |
12 ms |
2252 KB |
Output is correct |
9 |
Correct |
11 ms |
2292 KB |
Output is correct |
10 |
Correct |
26 ms |
2252 KB |
Output is correct |
11 |
Correct |
29 ms |
2252 KB |
Output is correct |
12 |
Correct |
29 ms |
2252 KB |
Output is correct |
13 |
Correct |
26 ms |
2292 KB |
Output is correct |
14 |
Correct |
25 ms |
2292 KB |
Output is correct |
15 |
Correct |
27 ms |
2292 KB |
Output is correct |
16 |
Correct |
32 ms |
2284 KB |
Output is correct |
17 |
Correct |
17 ms |
2296 KB |
Output is correct |
18 |
Correct |
22 ms |
2292 KB |
Output is correct |
19 |
Correct |
27 ms |
2288 KB |
Output is correct |
20 |
Correct |
28 ms |
2288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
5 ms |
2252 KB |
Output is correct |
5 |
Correct |
12 ms |
2296 KB |
Output is correct |
6 |
Correct |
8 ms |
2252 KB |
Output is correct |
7 |
Correct |
8 ms |
2288 KB |
Output is correct |
8 |
Correct |
12 ms |
2252 KB |
Output is correct |
9 |
Correct |
11 ms |
2292 KB |
Output is correct |
10 |
Correct |
26 ms |
2252 KB |
Output is correct |
11 |
Correct |
29 ms |
2252 KB |
Output is correct |
12 |
Correct |
29 ms |
2252 KB |
Output is correct |
13 |
Correct |
26 ms |
2292 KB |
Output is correct |
14 |
Correct |
25 ms |
2292 KB |
Output is correct |
15 |
Correct |
27 ms |
2292 KB |
Output is correct |
16 |
Correct |
32 ms |
2284 KB |
Output is correct |
17 |
Correct |
17 ms |
2296 KB |
Output is correct |
18 |
Correct |
22 ms |
2292 KB |
Output is correct |
19 |
Correct |
27 ms |
2288 KB |
Output is correct |
20 |
Correct |
28 ms |
2288 KB |
Output is correct |
21 |
Correct |
57 ms |
2288 KB |
Output is correct |
22 |
Incorrect |
62 ms |
2252 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
5 ms |
2252 KB |
Output is correct |
5 |
Correct |
12 ms |
2296 KB |
Output is correct |
6 |
Correct |
8 ms |
2252 KB |
Output is correct |
7 |
Correct |
8 ms |
2288 KB |
Output is correct |
8 |
Correct |
12 ms |
2252 KB |
Output is correct |
9 |
Correct |
11 ms |
2292 KB |
Output is correct |
10 |
Correct |
26 ms |
2252 KB |
Output is correct |
11 |
Correct |
29 ms |
2252 KB |
Output is correct |
12 |
Correct |
29 ms |
2252 KB |
Output is correct |
13 |
Correct |
26 ms |
2292 KB |
Output is correct |
14 |
Correct |
25 ms |
2292 KB |
Output is correct |
15 |
Correct |
27 ms |
2292 KB |
Output is correct |
16 |
Correct |
32 ms |
2284 KB |
Output is correct |
17 |
Correct |
17 ms |
2296 KB |
Output is correct |
18 |
Correct |
22 ms |
2292 KB |
Output is correct |
19 |
Correct |
27 ms |
2288 KB |
Output is correct |
20 |
Correct |
28 ms |
2288 KB |
Output is correct |
21 |
Correct |
57 ms |
2288 KB |
Output is correct |
22 |
Incorrect |
62 ms |
2252 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
5 ms |
2252 KB |
Output is correct |
5 |
Correct |
12 ms |
2296 KB |
Output is correct |
6 |
Correct |
8 ms |
2252 KB |
Output is correct |
7 |
Correct |
8 ms |
2288 KB |
Output is correct |
8 |
Correct |
12 ms |
2252 KB |
Output is correct |
9 |
Correct |
11 ms |
2292 KB |
Output is correct |
10 |
Correct |
26 ms |
2252 KB |
Output is correct |
11 |
Correct |
29 ms |
2252 KB |
Output is correct |
12 |
Correct |
29 ms |
2252 KB |
Output is correct |
13 |
Correct |
26 ms |
2292 KB |
Output is correct |
14 |
Correct |
25 ms |
2292 KB |
Output is correct |
15 |
Correct |
27 ms |
2292 KB |
Output is correct |
16 |
Correct |
32 ms |
2284 KB |
Output is correct |
17 |
Correct |
17 ms |
2296 KB |
Output is correct |
18 |
Correct |
22 ms |
2292 KB |
Output is correct |
19 |
Correct |
27 ms |
2288 KB |
Output is correct |
20 |
Correct |
28 ms |
2288 KB |
Output is correct |
21 |
Correct |
57 ms |
2288 KB |
Output is correct |
22 |
Incorrect |
62 ms |
2252 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
5 ms |
2252 KB |
Output is correct |
5 |
Correct |
12 ms |
2296 KB |
Output is correct |
6 |
Correct |
8 ms |
2252 KB |
Output is correct |
7 |
Correct |
8 ms |
2288 KB |
Output is correct |
8 |
Correct |
12 ms |
2252 KB |
Output is correct |
9 |
Correct |
11 ms |
2292 KB |
Output is correct |
10 |
Correct |
26 ms |
2252 KB |
Output is correct |
11 |
Correct |
29 ms |
2252 KB |
Output is correct |
12 |
Correct |
29 ms |
2252 KB |
Output is correct |
13 |
Correct |
26 ms |
2292 KB |
Output is correct |
14 |
Correct |
25 ms |
2292 KB |
Output is correct |
15 |
Correct |
27 ms |
2292 KB |
Output is correct |
16 |
Correct |
32 ms |
2284 KB |
Output is correct |
17 |
Correct |
17 ms |
2296 KB |
Output is correct |
18 |
Correct |
22 ms |
2292 KB |
Output is correct |
19 |
Correct |
27 ms |
2288 KB |
Output is correct |
20 |
Correct |
28 ms |
2288 KB |
Output is correct |
21 |
Correct |
57 ms |
2288 KB |
Output is correct |
22 |
Incorrect |
62 ms |
2252 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |