#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 ii mod = {1e9 + 7, 1e9 + 21};
ii dp[N * N];
int n, sum;
int a[N], cnt[N * N];
void fix(int &a, const int &mod)
{
if(a >= mod) a -= mod;
if(a < 0) a += mod;
}
void add(int x)
{
for(int i = sum; i >= x; i--)
{
dp[i].F += dp[i - x].F;
dp[i].S += dp[i - x].S;
fix(dp[i].F, mod.F), fix(dp[i].S, mod.S);
}
}
void del(int x)
{
for(int i = x; i <= sum; i++)
{
dp[i].F -= dp[i - x].F;
dp[i].S -= dp[i - x].S;
fix(dp[i].F, mod.F), fix(dp[i].S, mod.S);
}
}
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, 1};
for(int i = 1; i <= n; i++)
add(a[i]);
if(dp[sum].F == 0 && dp[sum].S == 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].F != 0 || dp[i].S != 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
3 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 |
7 ms |
392 KB |
Output is correct |
25 |
Correct |
8 ms |
400 KB |
Output is correct |
26 |
Correct |
9 ms |
340 KB |
Output is correct |
27 |
Correct |
7 ms |
340 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
6 ms |
340 KB |
Output is correct |
30 |
Correct |
6 ms |
340 KB |
Output is correct |
31 |
Correct |
9 ms |
340 KB |
Output is correct |
32 |
Correct |
7 ms |
340 KB |
Output is correct |
33 |
Correct |
5 ms |
340 KB |
Output is correct |
34 |
Correct |
5 ms |
340 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
3 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 |
7 ms |
392 KB |
Output is correct |
25 |
Correct |
8 ms |
400 KB |
Output is correct |
26 |
Correct |
9 ms |
340 KB |
Output is correct |
27 |
Correct |
7 ms |
340 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
6 ms |
340 KB |
Output is correct |
30 |
Correct |
6 ms |
340 KB |
Output is correct |
31 |
Correct |
9 ms |
340 KB |
Output is correct |
32 |
Correct |
7 ms |
340 KB |
Output is correct |
33 |
Correct |
5 ms |
340 KB |
Output is correct |
34 |
Correct |
5 ms |
340 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
340 KB |
Output is correct |
37 |
Correct |
50 ms |
528 KB |
Output is correct |
38 |
Correct |
51 ms |
588 KB |
Output is correct |
39 |
Correct |
38 ms |
700 KB |
Output is correct |
40 |
Correct |
112 ms |
692 KB |
Output is correct |
41 |
Correct |
58 ms |
880 KB |
Output is correct |
42 |
Correct |
101 ms |
704 KB |
Output is correct |
43 |
Correct |
164 ms |
1228 KB |
Output is correct |
44 |
Correct |
168 ms |
1056 KB |
Output is correct |
45 |
Correct |
175 ms |
1140 KB |
Output is correct |
46 |
Correct |
68 ms |
576 KB |
Output is correct |
47 |
Correct |
110 ms |
704 KB |
Output is correct |
48 |
Correct |
152 ms |
1044 KB |
Output is correct |
49 |
Correct |
108 ms |
796 KB |
Output is correct |
50 |
Correct |
110 ms |
692 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
215 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
3 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 |
7 ms |
392 KB |
Output is correct |
25 |
Correct |
8 ms |
400 KB |
Output is correct |
26 |
Correct |
9 ms |
340 KB |
Output is correct |
27 |
Correct |
7 ms |
340 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
6 ms |
340 KB |
Output is correct |
30 |
Correct |
6 ms |
340 KB |
Output is correct |
31 |
Correct |
9 ms |
340 KB |
Output is correct |
32 |
Correct |
7 ms |
340 KB |
Output is correct |
33 |
Correct |
5 ms |
340 KB |
Output is correct |
34 |
Correct |
5 ms |
340 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
340 KB |
Output is correct |
37 |
Correct |
50 ms |
528 KB |
Output is correct |
38 |
Correct |
51 ms |
588 KB |
Output is correct |
39 |
Correct |
38 ms |
700 KB |
Output is correct |
40 |
Correct |
112 ms |
692 KB |
Output is correct |
41 |
Correct |
58 ms |
880 KB |
Output is correct |
42 |
Correct |
101 ms |
704 KB |
Output is correct |
43 |
Correct |
164 ms |
1228 KB |
Output is correct |
44 |
Correct |
168 ms |
1056 KB |
Output is correct |
45 |
Correct |
175 ms |
1140 KB |
Output is correct |
46 |
Correct |
68 ms |
576 KB |
Output is correct |
47 |
Correct |
110 ms |
704 KB |
Output is correct |
48 |
Correct |
152 ms |
1044 KB |
Output is correct |
49 |
Correct |
108 ms |
796 KB |
Output is correct |
50 |
Correct |
110 ms |
692 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
215 ms |
1244 KB |
Output is correct |
53 |
Correct |
182 ms |
1020 KB |
Output is correct |
54 |
Correct |
252 ms |
1136 KB |
Output is correct |
55 |
Correct |
498 ms |
1776 KB |
Output is correct |
56 |
Correct |
214 ms |
1132 KB |
Output is correct |
57 |
Correct |
512 ms |
1872 KB |
Output is correct |
58 |
Correct |
276 ms |
1176 KB |
Output is correct |
59 |
Correct |
351 ms |
1296 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
377 ms |
1492 KB |
Output is correct |
62 |
Correct |
381 ms |
1588 KB |
Output is correct |
63 |
Correct |
437 ms |
1636 KB |
Output is correct |
64 |
Correct |
396 ms |
1744 KB |
Output is correct |
65 |
Correct |
48 ms |
696 KB |
Output is correct |
66 |
Correct |
75 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
3 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 |
7 ms |
392 KB |
Output is correct |
25 |
Correct |
8 ms |
400 KB |
Output is correct |
26 |
Correct |
9 ms |
340 KB |
Output is correct |
27 |
Correct |
7 ms |
340 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
6 ms |
340 KB |
Output is correct |
30 |
Correct |
6 ms |
340 KB |
Output is correct |
31 |
Correct |
9 ms |
340 KB |
Output is correct |
32 |
Correct |
7 ms |
340 KB |
Output is correct |
33 |
Correct |
5 ms |
340 KB |
Output is correct |
34 |
Correct |
5 ms |
340 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
340 KB |
Output is correct |
37 |
Correct |
50 ms |
528 KB |
Output is correct |
38 |
Correct |
51 ms |
588 KB |
Output is correct |
39 |
Correct |
38 ms |
700 KB |
Output is correct |
40 |
Correct |
112 ms |
692 KB |
Output is correct |
41 |
Correct |
58 ms |
880 KB |
Output is correct |
42 |
Correct |
101 ms |
704 KB |
Output is correct |
43 |
Correct |
164 ms |
1228 KB |
Output is correct |
44 |
Correct |
168 ms |
1056 KB |
Output is correct |
45 |
Correct |
175 ms |
1140 KB |
Output is correct |
46 |
Correct |
68 ms |
576 KB |
Output is correct |
47 |
Correct |
110 ms |
704 KB |
Output is correct |
48 |
Correct |
152 ms |
1044 KB |
Output is correct |
49 |
Correct |
108 ms |
796 KB |
Output is correct |
50 |
Correct |
110 ms |
692 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
215 ms |
1244 KB |
Output is correct |
53 |
Correct |
182 ms |
1020 KB |
Output is correct |
54 |
Correct |
252 ms |
1136 KB |
Output is correct |
55 |
Correct |
498 ms |
1776 KB |
Output is correct |
56 |
Correct |
214 ms |
1132 KB |
Output is correct |
57 |
Correct |
512 ms |
1872 KB |
Output is correct |
58 |
Correct |
276 ms |
1176 KB |
Output is correct |
59 |
Correct |
351 ms |
1296 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
377 ms |
1492 KB |
Output is correct |
62 |
Correct |
381 ms |
1588 KB |
Output is correct |
63 |
Correct |
437 ms |
1636 KB |
Output is correct |
64 |
Correct |
396 ms |
1744 KB |
Output is correct |
65 |
Correct |
48 ms |
696 KB |
Output is correct |
66 |
Correct |
75 ms |
716 KB |
Output is correct |
67 |
Correct |
397 ms |
1524 KB |
Output is correct |
68 |
Correct |
138 ms |
796 KB |
Output is correct |
69 |
Execution timed out |
1079 ms |
1904 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |