#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <bitset>
#include <set>
#include <map>
typedef long long llong;
const int MAXN = 350 + 10;
const int MAXSUM = 350*350*2 + 10;
const int INF = 1e9;
int a[MAXN], n;
std::vector <int> values;
std::bitset <MAXSUM> bs, ans;
void getBitset(int missing)
{
bs.reset();
bs[MAXSUM / 2] = 1;
for (int i = 1 ; i <= n ; ++i)
{
if (i == missing) continue;
bs = ((bs << a[i]) | (bs >> a[i]));
}
}
void solve()
{
ans.set();
bs[MAXSUM / 2] = 1;
for (int i = 1 ; i <= n ; ++i)
{
bs = ((bs << a[i]) | (bs >> a[i]));
}
if (!bs[MAXSUM / 2])
{
std::cout << 0 << '\n';
return;
}
for (int i = 1 ; i <= n ; ++i)
{
getBitset(i);
ans &= bs;
}
for (int i = 1 ; i <= MAXSUM - MAXSUM/2 - 1 ; ++i)
{
if (ans[MAXSUM / 2 + i] || ans[MAXSUM / 2 - i])
{
values.push_back(i);
}
}
std::cout << values.size() << '\n';
for (const int &i : values)
{
std::cout << i << ' ';
}
std::cout << '\n';
}
void read()
{
std::cin >> n;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
}
void fastIO()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIO();
read();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
12 ms |
468 KB |
Output is correct |
11 |
Correct |
13 ms |
560 KB |
Output is correct |
12 |
Correct |
14 ms |
468 KB |
Output is correct |
13 |
Correct |
11 ms |
552 KB |
Output is correct |
14 |
Correct |
12 ms |
468 KB |
Output is correct |
15 |
Correct |
11 ms |
552 KB |
Output is correct |
16 |
Correct |
12 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
8 ms |
468 KB |
Output is correct |
19 |
Correct |
9 ms |
556 KB |
Output is correct |
20 |
Correct |
16 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
12 ms |
468 KB |
Output is correct |
11 |
Correct |
13 ms |
560 KB |
Output is correct |
12 |
Correct |
14 ms |
468 KB |
Output is correct |
13 |
Correct |
11 ms |
552 KB |
Output is correct |
14 |
Correct |
12 ms |
468 KB |
Output is correct |
15 |
Correct |
11 ms |
552 KB |
Output is correct |
16 |
Correct |
12 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
8 ms |
468 KB |
Output is correct |
19 |
Correct |
9 ms |
556 KB |
Output is correct |
20 |
Correct |
16 ms |
468 KB |
Output is correct |
21 |
Correct |
52 ms |
536 KB |
Output is correct |
22 |
Correct |
72 ms |
548 KB |
Output is correct |
23 |
Correct |
34 ms |
536 KB |
Output is correct |
24 |
Correct |
112 ms |
536 KB |
Output is correct |
25 |
Correct |
120 ms |
532 KB |
Output is correct |
26 |
Correct |
126 ms |
544 KB |
Output is correct |
27 |
Correct |
127 ms |
536 KB |
Output is correct |
28 |
Correct |
127 ms |
544 KB |
Output is correct |
29 |
Correct |
132 ms |
540 KB |
Output is correct |
30 |
Correct |
128 ms |
468 KB |
Output is correct |
31 |
Correct |
135 ms |
536 KB |
Output is correct |
32 |
Correct |
133 ms |
536 KB |
Output is correct |
33 |
Correct |
133 ms |
536 KB |
Output is correct |
34 |
Correct |
130 ms |
468 KB |
Output is correct |
35 |
Correct |
127 ms |
532 KB |
Output is correct |
36 |
Correct |
127 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
12 ms |
468 KB |
Output is correct |
11 |
Correct |
13 ms |
560 KB |
Output is correct |
12 |
Correct |
14 ms |
468 KB |
Output is correct |
13 |
Correct |
11 ms |
552 KB |
Output is correct |
14 |
Correct |
12 ms |
468 KB |
Output is correct |
15 |
Correct |
11 ms |
552 KB |
Output is correct |
16 |
Correct |
12 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
8 ms |
468 KB |
Output is correct |
19 |
Correct |
9 ms |
556 KB |
Output is correct |
20 |
Correct |
16 ms |
468 KB |
Output is correct |
21 |
Correct |
52 ms |
536 KB |
Output is correct |
22 |
Correct |
72 ms |
548 KB |
Output is correct |
23 |
Correct |
34 ms |
536 KB |
Output is correct |
24 |
Correct |
112 ms |
536 KB |
Output is correct |
25 |
Correct |
120 ms |
532 KB |
Output is correct |
26 |
Correct |
126 ms |
544 KB |
Output is correct |
27 |
Correct |
127 ms |
536 KB |
Output is correct |
28 |
Correct |
127 ms |
544 KB |
Output is correct |
29 |
Correct |
132 ms |
540 KB |
Output is correct |
30 |
Correct |
128 ms |
468 KB |
Output is correct |
31 |
Correct |
135 ms |
536 KB |
Output is correct |
32 |
Correct |
133 ms |
536 KB |
Output is correct |
33 |
Correct |
133 ms |
536 KB |
Output is correct |
34 |
Correct |
130 ms |
468 KB |
Output is correct |
35 |
Correct |
127 ms |
532 KB |
Output is correct |
36 |
Correct |
127 ms |
532 KB |
Output is correct |
37 |
Correct |
518 ms |
664 KB |
Output is correct |
38 |
Correct |
497 ms |
668 KB |
Output is correct |
39 |
Correct |
773 ms |
540 KB |
Output is correct |
40 |
Correct |
913 ms |
664 KB |
Output is correct |
41 |
Correct |
912 ms |
540 KB |
Output is correct |
42 |
Correct |
799 ms |
668 KB |
Output is correct |
43 |
Correct |
760 ms |
936 KB |
Output is correct |
44 |
Correct |
777 ms |
932 KB |
Output is correct |
45 |
Correct |
780 ms |
972 KB |
Output is correct |
46 |
Correct |
905 ms |
548 KB |
Output is correct |
47 |
Correct |
783 ms |
664 KB |
Output is correct |
48 |
Correct |
801 ms |
844 KB |
Output is correct |
49 |
Correct |
783 ms |
540 KB |
Output is correct |
50 |
Correct |
787 ms |
676 KB |
Output is correct |
51 |
Correct |
4 ms |
472 KB |
Output is correct |
52 |
Correct |
909 ms |
932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
12 ms |
468 KB |
Output is correct |
11 |
Correct |
13 ms |
560 KB |
Output is correct |
12 |
Correct |
14 ms |
468 KB |
Output is correct |
13 |
Correct |
11 ms |
552 KB |
Output is correct |
14 |
Correct |
12 ms |
468 KB |
Output is correct |
15 |
Correct |
11 ms |
552 KB |
Output is correct |
16 |
Correct |
12 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
8 ms |
468 KB |
Output is correct |
19 |
Correct |
9 ms |
556 KB |
Output is correct |
20 |
Correct |
16 ms |
468 KB |
Output is correct |
21 |
Correct |
52 ms |
536 KB |
Output is correct |
22 |
Correct |
72 ms |
548 KB |
Output is correct |
23 |
Correct |
34 ms |
536 KB |
Output is correct |
24 |
Correct |
112 ms |
536 KB |
Output is correct |
25 |
Correct |
120 ms |
532 KB |
Output is correct |
26 |
Correct |
126 ms |
544 KB |
Output is correct |
27 |
Correct |
127 ms |
536 KB |
Output is correct |
28 |
Correct |
127 ms |
544 KB |
Output is correct |
29 |
Correct |
132 ms |
540 KB |
Output is correct |
30 |
Correct |
128 ms |
468 KB |
Output is correct |
31 |
Correct |
135 ms |
536 KB |
Output is correct |
32 |
Correct |
133 ms |
536 KB |
Output is correct |
33 |
Correct |
133 ms |
536 KB |
Output is correct |
34 |
Correct |
130 ms |
468 KB |
Output is correct |
35 |
Correct |
127 ms |
532 KB |
Output is correct |
36 |
Correct |
127 ms |
532 KB |
Output is correct |
37 |
Correct |
518 ms |
664 KB |
Output is correct |
38 |
Correct |
497 ms |
668 KB |
Output is correct |
39 |
Correct |
773 ms |
540 KB |
Output is correct |
40 |
Correct |
913 ms |
664 KB |
Output is correct |
41 |
Correct |
912 ms |
540 KB |
Output is correct |
42 |
Correct |
799 ms |
668 KB |
Output is correct |
43 |
Correct |
760 ms |
936 KB |
Output is correct |
44 |
Correct |
777 ms |
932 KB |
Output is correct |
45 |
Correct |
780 ms |
972 KB |
Output is correct |
46 |
Correct |
905 ms |
548 KB |
Output is correct |
47 |
Correct |
783 ms |
664 KB |
Output is correct |
48 |
Correct |
801 ms |
844 KB |
Output is correct |
49 |
Correct |
783 ms |
540 KB |
Output is correct |
50 |
Correct |
787 ms |
676 KB |
Output is correct |
51 |
Correct |
4 ms |
472 KB |
Output is correct |
52 |
Correct |
909 ms |
932 KB |
Output is correct |
53 |
Execution timed out |
1086 ms |
468 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
12 ms |
468 KB |
Output is correct |
11 |
Correct |
13 ms |
560 KB |
Output is correct |
12 |
Correct |
14 ms |
468 KB |
Output is correct |
13 |
Correct |
11 ms |
552 KB |
Output is correct |
14 |
Correct |
12 ms |
468 KB |
Output is correct |
15 |
Correct |
11 ms |
552 KB |
Output is correct |
16 |
Correct |
12 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
8 ms |
468 KB |
Output is correct |
19 |
Correct |
9 ms |
556 KB |
Output is correct |
20 |
Correct |
16 ms |
468 KB |
Output is correct |
21 |
Correct |
52 ms |
536 KB |
Output is correct |
22 |
Correct |
72 ms |
548 KB |
Output is correct |
23 |
Correct |
34 ms |
536 KB |
Output is correct |
24 |
Correct |
112 ms |
536 KB |
Output is correct |
25 |
Correct |
120 ms |
532 KB |
Output is correct |
26 |
Correct |
126 ms |
544 KB |
Output is correct |
27 |
Correct |
127 ms |
536 KB |
Output is correct |
28 |
Correct |
127 ms |
544 KB |
Output is correct |
29 |
Correct |
132 ms |
540 KB |
Output is correct |
30 |
Correct |
128 ms |
468 KB |
Output is correct |
31 |
Correct |
135 ms |
536 KB |
Output is correct |
32 |
Correct |
133 ms |
536 KB |
Output is correct |
33 |
Correct |
133 ms |
536 KB |
Output is correct |
34 |
Correct |
130 ms |
468 KB |
Output is correct |
35 |
Correct |
127 ms |
532 KB |
Output is correct |
36 |
Correct |
127 ms |
532 KB |
Output is correct |
37 |
Correct |
518 ms |
664 KB |
Output is correct |
38 |
Correct |
497 ms |
668 KB |
Output is correct |
39 |
Correct |
773 ms |
540 KB |
Output is correct |
40 |
Correct |
913 ms |
664 KB |
Output is correct |
41 |
Correct |
912 ms |
540 KB |
Output is correct |
42 |
Correct |
799 ms |
668 KB |
Output is correct |
43 |
Correct |
760 ms |
936 KB |
Output is correct |
44 |
Correct |
777 ms |
932 KB |
Output is correct |
45 |
Correct |
780 ms |
972 KB |
Output is correct |
46 |
Correct |
905 ms |
548 KB |
Output is correct |
47 |
Correct |
783 ms |
664 KB |
Output is correct |
48 |
Correct |
801 ms |
844 KB |
Output is correct |
49 |
Correct |
783 ms |
540 KB |
Output is correct |
50 |
Correct |
787 ms |
676 KB |
Output is correct |
51 |
Correct |
4 ms |
472 KB |
Output is correct |
52 |
Correct |
909 ms |
932 KB |
Output is correct |
53 |
Execution timed out |
1086 ms |
468 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |