#include <bits/stdc++.h>
using namespace std;
const int maxN = 500;
const int maxS = 350 * 350;
int v[maxN + 1];
bitset<maxS + 1> pos1n[maxN + 1], posn1[maxN + 2];
bitset<maxS + 1> pos, tim, timTemp;
int main() {
int n, s = 0;
cin >> n;
for ( int i = 1; i <= n; i++ )
cin >> v[i], s += v[i];
pos1n[0][0] = true;
for ( int i = 1; i <= n; i++ )
pos1n[i] = (pos1n[i - 1] | (pos1n[i - 1] << v[i]));
posn1[n + 1][0] = true;
for ( int i = n; i >= 1; i-- )
posn1[i] = (posn1[i + 1] | (posn1[i + 1] << v[i]));
if ( s % 2 != 0 || !pos1n[n][s / 2] ) {
cout << 0;
return 0;
}
for ( int i = 0; i <= s; i++ )
tim[i] = true;
for ( int r = 1; r <= n; r++ ) {
pos = pos1n[r - 1];
for ( int i = 0; i <= s; i++ ) {
if ( posn1[r + 1][i] )
pos |= (pos1n[r - 1] << i);
}
timTemp.reset();
for ( int i = 0; i <= s; i++ ) {
if ( pos[i] )
timTemp[abs( s - v[r] - i - i )] = true;
}
tim &= timTemp;
}
tim[0] = false;
cout << tim.count() << "\n";
for ( int i = 0; i <= s; i++ ) {
if ( tim[i] )
cout << i << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
8 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
8 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
1236 KB |
Output is correct |
11 |
Correct |
14 ms |
1296 KB |
Output is correct |
12 |
Correct |
10 ms |
1236 KB |
Output is correct |
13 |
Correct |
10 ms |
1108 KB |
Output is correct |
14 |
Correct |
17 ms |
1232 KB |
Output is correct |
15 |
Correct |
12 ms |
1236 KB |
Output is correct |
16 |
Correct |
14 ms |
1236 KB |
Output is correct |
17 |
Correct |
5 ms |
852 KB |
Output is correct |
18 |
Correct |
10 ms |
1112 KB |
Output is correct |
19 |
Correct |
12 ms |
1108 KB |
Output is correct |
20 |
Correct |
4 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
8 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
1236 KB |
Output is correct |
11 |
Correct |
14 ms |
1296 KB |
Output is correct |
12 |
Correct |
10 ms |
1236 KB |
Output is correct |
13 |
Correct |
10 ms |
1108 KB |
Output is correct |
14 |
Correct |
17 ms |
1232 KB |
Output is correct |
15 |
Correct |
12 ms |
1236 KB |
Output is correct |
16 |
Correct |
14 ms |
1236 KB |
Output is correct |
17 |
Correct |
5 ms |
852 KB |
Output is correct |
18 |
Correct |
10 ms |
1112 KB |
Output is correct |
19 |
Correct |
12 ms |
1108 KB |
Output is correct |
20 |
Correct |
4 ms |
1236 KB |
Output is correct |
21 |
Correct |
318 ms |
2296 KB |
Output is correct |
22 |
Correct |
377 ms |
2596 KB |
Output is correct |
23 |
Correct |
203 ms |
1868 KB |
Output is correct |
24 |
Correct |
742 ms |
3184 KB |
Output is correct |
25 |
Correct |
851 ms |
3192 KB |
Output is correct |
26 |
Correct |
972 ms |
3372 KB |
Output is correct |
27 |
Correct |
626 ms |
3492 KB |
Output is correct |
28 |
Correct |
439 ms |
3368 KB |
Output is correct |
29 |
Correct |
515 ms |
3372 KB |
Output is correct |
30 |
Correct |
869 ms |
3364 KB |
Output is correct |
31 |
Execution timed out |
1088 ms |
3372 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
8 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
1236 KB |
Output is correct |
11 |
Correct |
14 ms |
1296 KB |
Output is correct |
12 |
Correct |
10 ms |
1236 KB |
Output is correct |
13 |
Correct |
10 ms |
1108 KB |
Output is correct |
14 |
Correct |
17 ms |
1232 KB |
Output is correct |
15 |
Correct |
12 ms |
1236 KB |
Output is correct |
16 |
Correct |
14 ms |
1236 KB |
Output is correct |
17 |
Correct |
5 ms |
852 KB |
Output is correct |
18 |
Correct |
10 ms |
1112 KB |
Output is correct |
19 |
Correct |
12 ms |
1108 KB |
Output is correct |
20 |
Correct |
4 ms |
1236 KB |
Output is correct |
21 |
Correct |
318 ms |
2296 KB |
Output is correct |
22 |
Correct |
377 ms |
2596 KB |
Output is correct |
23 |
Correct |
203 ms |
1868 KB |
Output is correct |
24 |
Correct |
742 ms |
3184 KB |
Output is correct |
25 |
Correct |
851 ms |
3192 KB |
Output is correct |
26 |
Correct |
972 ms |
3372 KB |
Output is correct |
27 |
Correct |
626 ms |
3492 KB |
Output is correct |
28 |
Correct |
439 ms |
3368 KB |
Output is correct |
29 |
Correct |
515 ms |
3372 KB |
Output is correct |
30 |
Correct |
869 ms |
3364 KB |
Output is correct |
31 |
Execution timed out |
1088 ms |
3372 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
8 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
1236 KB |
Output is correct |
11 |
Correct |
14 ms |
1296 KB |
Output is correct |
12 |
Correct |
10 ms |
1236 KB |
Output is correct |
13 |
Correct |
10 ms |
1108 KB |
Output is correct |
14 |
Correct |
17 ms |
1232 KB |
Output is correct |
15 |
Correct |
12 ms |
1236 KB |
Output is correct |
16 |
Correct |
14 ms |
1236 KB |
Output is correct |
17 |
Correct |
5 ms |
852 KB |
Output is correct |
18 |
Correct |
10 ms |
1112 KB |
Output is correct |
19 |
Correct |
12 ms |
1108 KB |
Output is correct |
20 |
Correct |
4 ms |
1236 KB |
Output is correct |
21 |
Correct |
318 ms |
2296 KB |
Output is correct |
22 |
Correct |
377 ms |
2596 KB |
Output is correct |
23 |
Correct |
203 ms |
1868 KB |
Output is correct |
24 |
Correct |
742 ms |
3184 KB |
Output is correct |
25 |
Correct |
851 ms |
3192 KB |
Output is correct |
26 |
Correct |
972 ms |
3372 KB |
Output is correct |
27 |
Correct |
626 ms |
3492 KB |
Output is correct |
28 |
Correct |
439 ms |
3368 KB |
Output is correct |
29 |
Correct |
515 ms |
3372 KB |
Output is correct |
30 |
Correct |
869 ms |
3364 KB |
Output is correct |
31 |
Execution timed out |
1088 ms |
3372 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
8 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
1236 KB |
Output is correct |
11 |
Correct |
14 ms |
1296 KB |
Output is correct |
12 |
Correct |
10 ms |
1236 KB |
Output is correct |
13 |
Correct |
10 ms |
1108 KB |
Output is correct |
14 |
Correct |
17 ms |
1232 KB |
Output is correct |
15 |
Correct |
12 ms |
1236 KB |
Output is correct |
16 |
Correct |
14 ms |
1236 KB |
Output is correct |
17 |
Correct |
5 ms |
852 KB |
Output is correct |
18 |
Correct |
10 ms |
1112 KB |
Output is correct |
19 |
Correct |
12 ms |
1108 KB |
Output is correct |
20 |
Correct |
4 ms |
1236 KB |
Output is correct |
21 |
Correct |
318 ms |
2296 KB |
Output is correct |
22 |
Correct |
377 ms |
2596 KB |
Output is correct |
23 |
Correct |
203 ms |
1868 KB |
Output is correct |
24 |
Correct |
742 ms |
3184 KB |
Output is correct |
25 |
Correct |
851 ms |
3192 KB |
Output is correct |
26 |
Correct |
972 ms |
3372 KB |
Output is correct |
27 |
Correct |
626 ms |
3492 KB |
Output is correct |
28 |
Correct |
439 ms |
3368 KB |
Output is correct |
29 |
Correct |
515 ms |
3372 KB |
Output is correct |
30 |
Correct |
869 ms |
3364 KB |
Output is correct |
31 |
Execution timed out |
1088 ms |
3372 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |