#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
const ll maxn = 5e2 + 1, maxm = 3e5 + 1, maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31, block = 400;
using namespace std;
int n, sum;
int a[maxn], dp[maxm], cnt[maxm], ans[maxm];
int main(){
// ios_base::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
cin >> n;
dp[0] = 1;
for (int i = 1; i <= n; ++i){
cin >> a[i];
for(int j = maxm - 1; j >= a[i]; j--)
dp[j] += dp[j - a[i]];
sum += a[i];
}
if (sum % 2 != 0 || dp[sum / 2] == 0){
cout << 0;
return 0;
}
for (int i = 1; i <= n; ++i){
for (int j = a[i]; j <= maxm - 1; ++j){
dp[j] -= dp[j - a[i]];
}
for (int j = 0; j <= maxm - 1; ++j){
if (dp[j] > 0){
int f = j, s = sum - a[i] - j;
int rz = abs(f - s);
cnt[rz] = 1;
}
}
for (int j = 0; j <= maxm - 1; ++j){
if (cnt[j] > 0){
ans[j]++;
}
cnt[j] = 0;
}
for (int j = maxm - 1; j >= a[i]; --j){
dp[j] += dp[j - a[i]];
}
}
vector<int> v;
for (int i = 1; i <= maxm - 1; ++i){
if (ans[i] == n){
v.pb(i);
}
}
cout << v.size() << '\n';
for (auto it : v){
cout << it << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
8 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2740 KB |
Output is correct |
5 |
Correct |
14 ms |
2652 KB |
Output is correct |
6 |
Correct |
11 ms |
2636 KB |
Output is correct |
7 |
Correct |
9 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2652 KB |
Output is correct |
9 |
Correct |
12 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
8 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2740 KB |
Output is correct |
5 |
Correct |
14 ms |
2652 KB |
Output is correct |
6 |
Correct |
11 ms |
2636 KB |
Output is correct |
7 |
Correct |
9 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2652 KB |
Output is correct |
9 |
Correct |
12 ms |
2652 KB |
Output is correct |
10 |
Correct |
32 ms |
2636 KB |
Output is correct |
11 |
Correct |
34 ms |
2636 KB |
Output is correct |
12 |
Correct |
33 ms |
2636 KB |
Output is correct |
13 |
Correct |
30 ms |
2644 KB |
Output is correct |
14 |
Correct |
32 ms |
2640 KB |
Output is correct |
15 |
Correct |
32 ms |
2636 KB |
Output is correct |
16 |
Correct |
34 ms |
2636 KB |
Output is correct |
17 |
Correct |
22 ms |
2636 KB |
Output is correct |
18 |
Correct |
28 ms |
2648 KB |
Output is correct |
19 |
Correct |
29 ms |
2636 KB |
Output is correct |
20 |
Correct |
32 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
8 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2740 KB |
Output is correct |
5 |
Correct |
14 ms |
2652 KB |
Output is correct |
6 |
Correct |
11 ms |
2636 KB |
Output is correct |
7 |
Correct |
9 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2652 KB |
Output is correct |
9 |
Correct |
12 ms |
2652 KB |
Output is correct |
10 |
Correct |
32 ms |
2636 KB |
Output is correct |
11 |
Correct |
34 ms |
2636 KB |
Output is correct |
12 |
Correct |
33 ms |
2636 KB |
Output is correct |
13 |
Correct |
30 ms |
2644 KB |
Output is correct |
14 |
Correct |
32 ms |
2640 KB |
Output is correct |
15 |
Correct |
32 ms |
2636 KB |
Output is correct |
16 |
Correct |
34 ms |
2636 KB |
Output is correct |
17 |
Correct |
22 ms |
2636 KB |
Output is correct |
18 |
Correct |
28 ms |
2648 KB |
Output is correct |
19 |
Correct |
29 ms |
2636 KB |
Output is correct |
20 |
Correct |
32 ms |
2636 KB |
Output is correct |
21 |
Incorrect |
69 ms |
2640 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
8 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2740 KB |
Output is correct |
5 |
Correct |
14 ms |
2652 KB |
Output is correct |
6 |
Correct |
11 ms |
2636 KB |
Output is correct |
7 |
Correct |
9 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2652 KB |
Output is correct |
9 |
Correct |
12 ms |
2652 KB |
Output is correct |
10 |
Correct |
32 ms |
2636 KB |
Output is correct |
11 |
Correct |
34 ms |
2636 KB |
Output is correct |
12 |
Correct |
33 ms |
2636 KB |
Output is correct |
13 |
Correct |
30 ms |
2644 KB |
Output is correct |
14 |
Correct |
32 ms |
2640 KB |
Output is correct |
15 |
Correct |
32 ms |
2636 KB |
Output is correct |
16 |
Correct |
34 ms |
2636 KB |
Output is correct |
17 |
Correct |
22 ms |
2636 KB |
Output is correct |
18 |
Correct |
28 ms |
2648 KB |
Output is correct |
19 |
Correct |
29 ms |
2636 KB |
Output is correct |
20 |
Correct |
32 ms |
2636 KB |
Output is correct |
21 |
Incorrect |
69 ms |
2640 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
8 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2740 KB |
Output is correct |
5 |
Correct |
14 ms |
2652 KB |
Output is correct |
6 |
Correct |
11 ms |
2636 KB |
Output is correct |
7 |
Correct |
9 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2652 KB |
Output is correct |
9 |
Correct |
12 ms |
2652 KB |
Output is correct |
10 |
Correct |
32 ms |
2636 KB |
Output is correct |
11 |
Correct |
34 ms |
2636 KB |
Output is correct |
12 |
Correct |
33 ms |
2636 KB |
Output is correct |
13 |
Correct |
30 ms |
2644 KB |
Output is correct |
14 |
Correct |
32 ms |
2640 KB |
Output is correct |
15 |
Correct |
32 ms |
2636 KB |
Output is correct |
16 |
Correct |
34 ms |
2636 KB |
Output is correct |
17 |
Correct |
22 ms |
2636 KB |
Output is correct |
18 |
Correct |
28 ms |
2648 KB |
Output is correct |
19 |
Correct |
29 ms |
2636 KB |
Output is correct |
20 |
Correct |
32 ms |
2636 KB |
Output is correct |
21 |
Incorrect |
69 ms |
2640 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
8 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2740 KB |
Output is correct |
5 |
Correct |
14 ms |
2652 KB |
Output is correct |
6 |
Correct |
11 ms |
2636 KB |
Output is correct |
7 |
Correct |
9 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2652 KB |
Output is correct |
9 |
Correct |
12 ms |
2652 KB |
Output is correct |
10 |
Correct |
32 ms |
2636 KB |
Output is correct |
11 |
Correct |
34 ms |
2636 KB |
Output is correct |
12 |
Correct |
33 ms |
2636 KB |
Output is correct |
13 |
Correct |
30 ms |
2644 KB |
Output is correct |
14 |
Correct |
32 ms |
2640 KB |
Output is correct |
15 |
Correct |
32 ms |
2636 KB |
Output is correct |
16 |
Correct |
34 ms |
2636 KB |
Output is correct |
17 |
Correct |
22 ms |
2636 KB |
Output is correct |
18 |
Correct |
28 ms |
2648 KB |
Output is correct |
19 |
Correct |
29 ms |
2636 KB |
Output is correct |
20 |
Correct |
32 ms |
2636 KB |
Output is correct |
21 |
Incorrect |
69 ms |
2640 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |