#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 5e2 + 5;
const int NN = 500*500 + 5;
#define pb push_back
#define sz size()
#define ff first
#define ss second
vector <int> v, jog;
int n, a[N], dp[NN], san[NN], sum;
map <int, bool> m[NN];
int main () {
// freopen("input.txt", "r", stdin);
// freopen ("cykar.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
sum += a[i];
}
// for (int i = 1; i <= n; ++i) {
// cout << a[i] << " ";
// }
// return 0;
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = sum - a[i]; j >= 0; j--) {
if (dp[j]) {
dp[j + a[i]] = 1;
m[j + a[i]][a[i]] = 1;
for (auto jj : m[j]) {
m[j + a[i]][jj.ff] = 1;
}
}
}
}
if (sum % 2 == 1 or !dp[sum / 2]) {
cout << "0\n";
return 0;
}
for (int i = 0; i <= sum; ++i) {
if (dp[i]) {
v.pb (i);
}
}
for (int i = 1; i <= n; ++i) {
map <int, bool> mp;
for (int j : v) {
// j we sum - j
int grup1 = j;
int grup2 = sum - j;
if (m[grup1].find(a[i]) != m[grup1].end()) {
int sum1 = grup1 - a[i];
int variant = abs(sum1 - grup2);
if (mp.find (variant) == mp.end()) {
san[variant]++;
mp[variant] = 1;
}
}
}
}
for (int i = 0; i <= sum; ++i) {
if (san[i] == n) {
jog.pb (i);
}
}
cout << (int)jog.sz << "\n";
for (int i : jog) {
cout << i << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12952 KB |
Output is correct |
5 |
Correct |
4 ms |
13148 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12948 KB |
Output is correct |
8 |
Correct |
4 ms |
13148 KB |
Output is correct |
9 |
Correct |
3 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12952 KB |
Output is correct |
5 |
Correct |
4 ms |
13148 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12948 KB |
Output is correct |
8 |
Correct |
4 ms |
13148 KB |
Output is correct |
9 |
Correct |
3 ms |
12892 KB |
Output is correct |
10 |
Correct |
3 ms |
12948 KB |
Output is correct |
11 |
Correct |
3 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12892 KB |
Output is correct |
14 |
Correct |
4 ms |
12892 KB |
Output is correct |
15 |
Correct |
3 ms |
12892 KB |
Output is correct |
16 |
Correct |
3 ms |
12952 KB |
Output is correct |
17 |
Correct |
3 ms |
12892 KB |
Output is correct |
18 |
Correct |
3 ms |
12892 KB |
Output is correct |
19 |
Correct |
3 ms |
12908 KB |
Output is correct |
20 |
Correct |
2 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12952 KB |
Output is correct |
5 |
Correct |
4 ms |
13148 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12948 KB |
Output is correct |
8 |
Correct |
4 ms |
13148 KB |
Output is correct |
9 |
Correct |
3 ms |
12892 KB |
Output is correct |
10 |
Correct |
3 ms |
12948 KB |
Output is correct |
11 |
Correct |
3 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12892 KB |
Output is correct |
14 |
Correct |
4 ms |
12892 KB |
Output is correct |
15 |
Correct |
3 ms |
12892 KB |
Output is correct |
16 |
Correct |
3 ms |
12952 KB |
Output is correct |
17 |
Correct |
3 ms |
12892 KB |
Output is correct |
18 |
Correct |
3 ms |
12892 KB |
Output is correct |
19 |
Correct |
3 ms |
12908 KB |
Output is correct |
20 |
Correct |
2 ms |
12892 KB |
Output is correct |
21 |
Correct |
64 ms |
17888 KB |
Output is correct |
22 |
Correct |
81 ms |
19028 KB |
Output is correct |
23 |
Correct |
32 ms |
15964 KB |
Output is correct |
24 |
Correct |
147 ms |
22084 KB |
Output is correct |
25 |
Correct |
65 ms |
15128 KB |
Output is correct |
26 |
Correct |
76 ms |
15196 KB |
Output is correct |
27 |
Correct |
39 ms |
14168 KB |
Output is correct |
28 |
Correct |
26 ms |
13400 KB |
Output is correct |
29 |
Correct |
36 ms |
13660 KB |
Output is correct |
30 |
Correct |
294 ms |
29012 KB |
Output is correct |
31 |
Correct |
195 ms |
21676 KB |
Output is correct |
32 |
Correct |
177 ms |
22608 KB |
Output is correct |
33 |
Correct |
3 ms |
12892 KB |
Output is correct |
34 |
Correct |
4 ms |
12892 KB |
Output is correct |
35 |
Correct |
29 ms |
13404 KB |
Output is correct |
36 |
Correct |
176 ms |
23944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12952 KB |
Output is correct |
5 |
Correct |
4 ms |
13148 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12948 KB |
Output is correct |
8 |
Correct |
4 ms |
13148 KB |
Output is correct |
9 |
Correct |
3 ms |
12892 KB |
Output is correct |
10 |
Correct |
3 ms |
12948 KB |
Output is correct |
11 |
Correct |
3 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12892 KB |
Output is correct |
14 |
Correct |
4 ms |
12892 KB |
Output is correct |
15 |
Correct |
3 ms |
12892 KB |
Output is correct |
16 |
Correct |
3 ms |
12952 KB |
Output is correct |
17 |
Correct |
3 ms |
12892 KB |
Output is correct |
18 |
Correct |
3 ms |
12892 KB |
Output is correct |
19 |
Correct |
3 ms |
12908 KB |
Output is correct |
20 |
Correct |
2 ms |
12892 KB |
Output is correct |
21 |
Correct |
64 ms |
17888 KB |
Output is correct |
22 |
Correct |
81 ms |
19028 KB |
Output is correct |
23 |
Correct |
32 ms |
15964 KB |
Output is correct |
24 |
Correct |
147 ms |
22084 KB |
Output is correct |
25 |
Correct |
65 ms |
15128 KB |
Output is correct |
26 |
Correct |
76 ms |
15196 KB |
Output is correct |
27 |
Correct |
39 ms |
14168 KB |
Output is correct |
28 |
Correct |
26 ms |
13400 KB |
Output is correct |
29 |
Correct |
36 ms |
13660 KB |
Output is correct |
30 |
Correct |
294 ms |
29012 KB |
Output is correct |
31 |
Correct |
195 ms |
21676 KB |
Output is correct |
32 |
Correct |
177 ms |
22608 KB |
Output is correct |
33 |
Correct |
3 ms |
12892 KB |
Output is correct |
34 |
Correct |
4 ms |
12892 KB |
Output is correct |
35 |
Correct |
29 ms |
13404 KB |
Output is correct |
36 |
Correct |
176 ms |
23944 KB |
Output is correct |
37 |
Execution timed out |
1060 ms |
49204 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12952 KB |
Output is correct |
5 |
Correct |
4 ms |
13148 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12948 KB |
Output is correct |
8 |
Correct |
4 ms |
13148 KB |
Output is correct |
9 |
Correct |
3 ms |
12892 KB |
Output is correct |
10 |
Correct |
3 ms |
12948 KB |
Output is correct |
11 |
Correct |
3 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12892 KB |
Output is correct |
14 |
Correct |
4 ms |
12892 KB |
Output is correct |
15 |
Correct |
3 ms |
12892 KB |
Output is correct |
16 |
Correct |
3 ms |
12952 KB |
Output is correct |
17 |
Correct |
3 ms |
12892 KB |
Output is correct |
18 |
Correct |
3 ms |
12892 KB |
Output is correct |
19 |
Correct |
3 ms |
12908 KB |
Output is correct |
20 |
Correct |
2 ms |
12892 KB |
Output is correct |
21 |
Correct |
64 ms |
17888 KB |
Output is correct |
22 |
Correct |
81 ms |
19028 KB |
Output is correct |
23 |
Correct |
32 ms |
15964 KB |
Output is correct |
24 |
Correct |
147 ms |
22084 KB |
Output is correct |
25 |
Correct |
65 ms |
15128 KB |
Output is correct |
26 |
Correct |
76 ms |
15196 KB |
Output is correct |
27 |
Correct |
39 ms |
14168 KB |
Output is correct |
28 |
Correct |
26 ms |
13400 KB |
Output is correct |
29 |
Correct |
36 ms |
13660 KB |
Output is correct |
30 |
Correct |
294 ms |
29012 KB |
Output is correct |
31 |
Correct |
195 ms |
21676 KB |
Output is correct |
32 |
Correct |
177 ms |
22608 KB |
Output is correct |
33 |
Correct |
3 ms |
12892 KB |
Output is correct |
34 |
Correct |
4 ms |
12892 KB |
Output is correct |
35 |
Correct |
29 ms |
13404 KB |
Output is correct |
36 |
Correct |
176 ms |
23944 KB |
Output is correct |
37 |
Execution timed out |
1060 ms |
49204 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12952 KB |
Output is correct |
5 |
Correct |
4 ms |
13148 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12948 KB |
Output is correct |
8 |
Correct |
4 ms |
13148 KB |
Output is correct |
9 |
Correct |
3 ms |
12892 KB |
Output is correct |
10 |
Correct |
3 ms |
12948 KB |
Output is correct |
11 |
Correct |
3 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12892 KB |
Output is correct |
14 |
Correct |
4 ms |
12892 KB |
Output is correct |
15 |
Correct |
3 ms |
12892 KB |
Output is correct |
16 |
Correct |
3 ms |
12952 KB |
Output is correct |
17 |
Correct |
3 ms |
12892 KB |
Output is correct |
18 |
Correct |
3 ms |
12892 KB |
Output is correct |
19 |
Correct |
3 ms |
12908 KB |
Output is correct |
20 |
Correct |
2 ms |
12892 KB |
Output is correct |
21 |
Correct |
64 ms |
17888 KB |
Output is correct |
22 |
Correct |
81 ms |
19028 KB |
Output is correct |
23 |
Correct |
32 ms |
15964 KB |
Output is correct |
24 |
Correct |
147 ms |
22084 KB |
Output is correct |
25 |
Correct |
65 ms |
15128 KB |
Output is correct |
26 |
Correct |
76 ms |
15196 KB |
Output is correct |
27 |
Correct |
39 ms |
14168 KB |
Output is correct |
28 |
Correct |
26 ms |
13400 KB |
Output is correct |
29 |
Correct |
36 ms |
13660 KB |
Output is correct |
30 |
Correct |
294 ms |
29012 KB |
Output is correct |
31 |
Correct |
195 ms |
21676 KB |
Output is correct |
32 |
Correct |
177 ms |
22608 KB |
Output is correct |
33 |
Correct |
3 ms |
12892 KB |
Output is correct |
34 |
Correct |
4 ms |
12892 KB |
Output is correct |
35 |
Correct |
29 ms |
13404 KB |
Output is correct |
36 |
Correct |
176 ms |
23944 KB |
Output is correct |
37 |
Execution timed out |
1060 ms |
49204 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |