// In the Name of God
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)
#define itr iterator
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = b; i >= a; --i)
#define ub upper_bound
#define lb lower_bound
const int N = 5e2 + 5;
const int mod = 1e8 + 7;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const int pw = 257;
int n, a[N], sum, cnt[N * N];
bool dp[N * N];
vector<int> ans;
int main() {
#ifdef Madi
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base :: sync_with_stdio(false); cin.tie(NULL);
cin >> n;
rep(i, 1, n) {
cin >> a[i];
sum += a[i];
}
if (sum % 2 == 1)
return cout << 0, 0;
dp[0] = 1;
rep(i, 1, n)
per(s, 1, sum / 2)
if (s - a[i] >= 0)
dp[s] |= dp[s - a[i]];
if (!dp[sum / 2])
return cout << 0, 0;
rep(k, 1, n) {
memset(dp, 0, sizeof(dp));
dp[0] = 1;
rep(i, 1, n) {
if (i == k)
continue;
per(s, 1, sum)
if (s - a[i] >= 0)
dp[s] |= dp[s - a[i]];
}
rep(s, 1, sum)
if (dp[s])
++cnt[max(0, s * 2 - (sum - a[k]))];
}
rep(x, 1, sum)
if (cnt[x] == n)
ans.pb(x);
cout << sz(ans) << "\n";
for (auto it : ans)
cout << it << ' ';
#ifdef Madi
cerr << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
508 KB |
Output is correct |
14 |
Correct |
2 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
632 KB |
Output is correct |
18 |
Correct |
2 ms |
632 KB |
Output is correct |
19 |
Correct |
2 ms |
632 KB |
Output is correct |
20 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
508 KB |
Output is correct |
14 |
Correct |
2 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
632 KB |
Output is correct |
18 |
Correct |
2 ms |
632 KB |
Output is correct |
19 |
Correct |
2 ms |
632 KB |
Output is correct |
20 |
Correct |
3 ms |
632 KB |
Output is correct |
21 |
Correct |
11 ms |
636 KB |
Output is correct |
22 |
Correct |
16 ms |
632 KB |
Output is correct |
23 |
Correct |
7 ms |
632 KB |
Output is correct |
24 |
Correct |
31 ms |
632 KB |
Output is correct |
25 |
Correct |
57 ms |
632 KB |
Output is correct |
26 |
Correct |
66 ms |
632 KB |
Output is correct |
27 |
Correct |
61 ms |
664 KB |
Output is correct |
28 |
Correct |
65 ms |
636 KB |
Output is correct |
29 |
Correct |
69 ms |
632 KB |
Output is correct |
30 |
Correct |
38 ms |
632 KB |
Output is correct |
31 |
Correct |
55 ms |
632 KB |
Output is correct |
32 |
Correct |
36 ms |
760 KB |
Output is correct |
33 |
Correct |
70 ms |
760 KB |
Output is correct |
34 |
Correct |
70 ms |
632 KB |
Output is correct |
35 |
Correct |
68 ms |
632 KB |
Output is correct |
36 |
Correct |
35 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
508 KB |
Output is correct |
14 |
Correct |
2 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
632 KB |
Output is correct |
18 |
Correct |
2 ms |
632 KB |
Output is correct |
19 |
Correct |
2 ms |
632 KB |
Output is correct |
20 |
Correct |
3 ms |
632 KB |
Output is correct |
21 |
Correct |
11 ms |
636 KB |
Output is correct |
22 |
Correct |
16 ms |
632 KB |
Output is correct |
23 |
Correct |
7 ms |
632 KB |
Output is correct |
24 |
Correct |
31 ms |
632 KB |
Output is correct |
25 |
Correct |
57 ms |
632 KB |
Output is correct |
26 |
Correct |
66 ms |
632 KB |
Output is correct |
27 |
Correct |
61 ms |
664 KB |
Output is correct |
28 |
Correct |
65 ms |
636 KB |
Output is correct |
29 |
Correct |
69 ms |
632 KB |
Output is correct |
30 |
Correct |
38 ms |
632 KB |
Output is correct |
31 |
Correct |
55 ms |
632 KB |
Output is correct |
32 |
Correct |
36 ms |
760 KB |
Output is correct |
33 |
Correct |
70 ms |
760 KB |
Output is correct |
34 |
Correct |
70 ms |
632 KB |
Output is correct |
35 |
Correct |
68 ms |
632 KB |
Output is correct |
36 |
Correct |
35 ms |
632 KB |
Output is correct |
37 |
Correct |
573 ms |
888 KB |
Output is correct |
38 |
Correct |
534 ms |
888 KB |
Output is correct |
39 |
Execution timed out |
1072 ms |
760 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
508 KB |
Output is correct |
14 |
Correct |
2 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
632 KB |
Output is correct |
18 |
Correct |
2 ms |
632 KB |
Output is correct |
19 |
Correct |
2 ms |
632 KB |
Output is correct |
20 |
Correct |
3 ms |
632 KB |
Output is correct |
21 |
Correct |
11 ms |
636 KB |
Output is correct |
22 |
Correct |
16 ms |
632 KB |
Output is correct |
23 |
Correct |
7 ms |
632 KB |
Output is correct |
24 |
Correct |
31 ms |
632 KB |
Output is correct |
25 |
Correct |
57 ms |
632 KB |
Output is correct |
26 |
Correct |
66 ms |
632 KB |
Output is correct |
27 |
Correct |
61 ms |
664 KB |
Output is correct |
28 |
Correct |
65 ms |
636 KB |
Output is correct |
29 |
Correct |
69 ms |
632 KB |
Output is correct |
30 |
Correct |
38 ms |
632 KB |
Output is correct |
31 |
Correct |
55 ms |
632 KB |
Output is correct |
32 |
Correct |
36 ms |
760 KB |
Output is correct |
33 |
Correct |
70 ms |
760 KB |
Output is correct |
34 |
Correct |
70 ms |
632 KB |
Output is correct |
35 |
Correct |
68 ms |
632 KB |
Output is correct |
36 |
Correct |
35 ms |
632 KB |
Output is correct |
37 |
Correct |
573 ms |
888 KB |
Output is correct |
38 |
Correct |
534 ms |
888 KB |
Output is correct |
39 |
Execution timed out |
1072 ms |
760 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
508 KB |
Output is correct |
14 |
Correct |
2 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
632 KB |
Output is correct |
18 |
Correct |
2 ms |
632 KB |
Output is correct |
19 |
Correct |
2 ms |
632 KB |
Output is correct |
20 |
Correct |
3 ms |
632 KB |
Output is correct |
21 |
Correct |
11 ms |
636 KB |
Output is correct |
22 |
Correct |
16 ms |
632 KB |
Output is correct |
23 |
Correct |
7 ms |
632 KB |
Output is correct |
24 |
Correct |
31 ms |
632 KB |
Output is correct |
25 |
Correct |
57 ms |
632 KB |
Output is correct |
26 |
Correct |
66 ms |
632 KB |
Output is correct |
27 |
Correct |
61 ms |
664 KB |
Output is correct |
28 |
Correct |
65 ms |
636 KB |
Output is correct |
29 |
Correct |
69 ms |
632 KB |
Output is correct |
30 |
Correct |
38 ms |
632 KB |
Output is correct |
31 |
Correct |
55 ms |
632 KB |
Output is correct |
32 |
Correct |
36 ms |
760 KB |
Output is correct |
33 |
Correct |
70 ms |
760 KB |
Output is correct |
34 |
Correct |
70 ms |
632 KB |
Output is correct |
35 |
Correct |
68 ms |
632 KB |
Output is correct |
36 |
Correct |
35 ms |
632 KB |
Output is correct |
37 |
Correct |
573 ms |
888 KB |
Output is correct |
38 |
Correct |
534 ms |
888 KB |
Output is correct |
39 |
Execution timed out |
1072 ms |
760 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |