#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
const int N = 500 + 5;
const int mod = 1e9 + 21;
int dp[N * N];
int n, sum;
int a[N], cnt[N * N];
void fix(int &a)
{
if(a >= mod) a -= mod;
if(a < 0) a += mod;
}
void add(int x)
{
for(int i = sum; i >= x; i--)
{
dp[i] += dp[i - x];
fix(dp[i]);
}
}
void del(int x)
{
for(int i = x; i <= sum; i++)
{
dp[i] -= dp[i - x];
fix(dp[i]);
}
}
void solve()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i], sum += a[i];
if(sum & 1) cout << 0, exit(0);
int tmp = sum;
sum /= 2;
dp[0] = 1;
for(int i = 1; i <= n; i++)
add(a[i]);
if(dp[sum]== 0)
cout << 0, exit(0);
for(int i = 1; i <= n; i++)
{
del(a[i]);
tmp -= a[i];
vector<int> s;
for(int i = 0; i <= tmp / 2; i++) if(dp[i] != 0)
{
int team1 = i;
int team2 = tmp - team1;
cnt[abs(team1 - team2)]++;
}
tmp += a[i];
add(a[i]);
}
vector<int> res;
for(int i = 1; i <= 500 * 500; i++)
if(cnt[i] == n) res.pb(i);
cout << res.size() << '\n';
for(const int &x : res) cout << x << ' ';
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
388 KB |
Output is correct |
29 |
Correct |
4 ms |
340 KB |
Output is correct |
30 |
Correct |
4 ms |
340 KB |
Output is correct |
31 |
Correct |
9 ms |
376 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
9 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
388 KB |
Output is correct |
29 |
Correct |
4 ms |
340 KB |
Output is correct |
30 |
Correct |
4 ms |
340 KB |
Output is correct |
31 |
Correct |
9 ms |
376 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
9 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
24 ms |
588 KB |
Output is correct |
38 |
Correct |
23 ms |
500 KB |
Output is correct |
39 |
Correct |
33 ms |
596 KB |
Output is correct |
40 |
Correct |
50 ms |
640 KB |
Output is correct |
41 |
Correct |
46 ms |
740 KB |
Output is correct |
42 |
Correct |
46 ms |
620 KB |
Output is correct |
43 |
Correct |
78 ms |
1016 KB |
Output is correct |
44 |
Correct |
84 ms |
944 KB |
Output is correct |
45 |
Correct |
86 ms |
1024 KB |
Output is correct |
46 |
Correct |
32 ms |
468 KB |
Output is correct |
47 |
Correct |
54 ms |
632 KB |
Output is correct |
48 |
Correct |
78 ms |
924 KB |
Output is correct |
49 |
Correct |
93 ms |
692 KB |
Output is correct |
50 |
Correct |
51 ms |
716 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
215 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
388 KB |
Output is correct |
29 |
Correct |
4 ms |
340 KB |
Output is correct |
30 |
Correct |
4 ms |
340 KB |
Output is correct |
31 |
Correct |
9 ms |
376 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
9 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
24 ms |
588 KB |
Output is correct |
38 |
Correct |
23 ms |
500 KB |
Output is correct |
39 |
Correct |
33 ms |
596 KB |
Output is correct |
40 |
Correct |
50 ms |
640 KB |
Output is correct |
41 |
Correct |
46 ms |
740 KB |
Output is correct |
42 |
Correct |
46 ms |
620 KB |
Output is correct |
43 |
Correct |
78 ms |
1016 KB |
Output is correct |
44 |
Correct |
84 ms |
944 KB |
Output is correct |
45 |
Correct |
86 ms |
1024 KB |
Output is correct |
46 |
Correct |
32 ms |
468 KB |
Output is correct |
47 |
Correct |
54 ms |
632 KB |
Output is correct |
48 |
Correct |
78 ms |
924 KB |
Output is correct |
49 |
Correct |
93 ms |
692 KB |
Output is correct |
50 |
Correct |
51 ms |
716 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
215 ms |
1100 KB |
Output is correct |
53 |
Correct |
78 ms |
932 KB |
Output is correct |
54 |
Correct |
120 ms |
936 KB |
Output is correct |
55 |
Correct |
215 ms |
1488 KB |
Output is correct |
56 |
Correct |
98 ms |
1020 KB |
Output is correct |
57 |
Correct |
230 ms |
1572 KB |
Output is correct |
58 |
Correct |
131 ms |
1080 KB |
Output is correct |
59 |
Correct |
162 ms |
1152 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
178 ms |
1328 KB |
Output is correct |
62 |
Correct |
173 ms |
1388 KB |
Output is correct |
63 |
Correct |
185 ms |
1524 KB |
Output is correct |
64 |
Correct |
185 ms |
1420 KB |
Output is correct |
65 |
Correct |
43 ms |
596 KB |
Output is correct |
66 |
Correct |
43 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
388 KB |
Output is correct |
29 |
Correct |
4 ms |
340 KB |
Output is correct |
30 |
Correct |
4 ms |
340 KB |
Output is correct |
31 |
Correct |
9 ms |
376 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
9 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
24 ms |
588 KB |
Output is correct |
38 |
Correct |
23 ms |
500 KB |
Output is correct |
39 |
Correct |
33 ms |
596 KB |
Output is correct |
40 |
Correct |
50 ms |
640 KB |
Output is correct |
41 |
Correct |
46 ms |
740 KB |
Output is correct |
42 |
Correct |
46 ms |
620 KB |
Output is correct |
43 |
Correct |
78 ms |
1016 KB |
Output is correct |
44 |
Correct |
84 ms |
944 KB |
Output is correct |
45 |
Correct |
86 ms |
1024 KB |
Output is correct |
46 |
Correct |
32 ms |
468 KB |
Output is correct |
47 |
Correct |
54 ms |
632 KB |
Output is correct |
48 |
Correct |
78 ms |
924 KB |
Output is correct |
49 |
Correct |
93 ms |
692 KB |
Output is correct |
50 |
Correct |
51 ms |
716 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
215 ms |
1100 KB |
Output is correct |
53 |
Correct |
78 ms |
932 KB |
Output is correct |
54 |
Correct |
120 ms |
936 KB |
Output is correct |
55 |
Correct |
215 ms |
1488 KB |
Output is correct |
56 |
Correct |
98 ms |
1020 KB |
Output is correct |
57 |
Correct |
230 ms |
1572 KB |
Output is correct |
58 |
Correct |
131 ms |
1080 KB |
Output is correct |
59 |
Correct |
162 ms |
1152 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
178 ms |
1328 KB |
Output is correct |
62 |
Correct |
173 ms |
1388 KB |
Output is correct |
63 |
Correct |
185 ms |
1524 KB |
Output is correct |
64 |
Correct |
185 ms |
1420 KB |
Output is correct |
65 |
Correct |
43 ms |
596 KB |
Output is correct |
66 |
Correct |
43 ms |
620 KB |
Output is correct |
67 |
Correct |
172 ms |
1300 KB |
Output is correct |
68 |
Correct |
178 ms |
564 KB |
Output is correct |
69 |
Correct |
662 ms |
2760 KB |
Output is correct |
70 |
Correct |
407 ms |
1844 KB |
Output is correct |
71 |
Correct |
364 ms |
1812 KB |
Output is correct |
72 |
Correct |
362 ms |
944 KB |
Output is correct |
73 |
Correct |
354 ms |
944 KB |
Output is correct |
74 |
Correct |
649 ms |
2780 KB |
Output is correct |
75 |
Correct |
489 ms |
2356 KB |
Output is correct |
76 |
Correct |
650 ms |
2900 KB |
Output is correct |
77 |
Correct |
680 ms |
2956 KB |
Output is correct |