#include <bits/stdc++.h>
using namespace std;
const int MOD1 = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int MOD3 = 998244353;
const int MOD4 = 999990011;
template<unsigned int MOD>
struct mint {
int v;
mint() {}
mint(long long val) : v(val % MOD + (val < 0) * MOD) {}
mint<MOD>& operator += (mint<MOD> other) {
*this = mint(v + other.v);
return *this;
}
mint<MOD>& operator -= (mint<MOD> other) {
*this = mint(v - other.v);
return *this;
}
};
const int N = 370;
const int A = 123000;
int lim = 0;
mint<MOD1> dp1[A]{1};
mint<MOD2> dp2[A]{1};
mint<MOD2> dp3[A]{1};
mint<MOD2> dp4[A]{1};
int sum = 0;
void add(int val) {
sum += val;
for (int i = lim; i >= val; i--) {
dp1[i] += dp1[i - val];
dp2[i] += dp2[i - val];
dp3[i] += dp3[i - val];
dp4[i] += dp4[i - val];
}
}
bool check(int sum) {
assert(0 <= sum && sum <= lim);
bool flag = true;
flag &= (dp1[sum].v > 0);
flag &= (dp2[sum].v > 0);
flag &= (dp3[sum].v > 0);
flag &= (dp4[sum].v > 0);
return flag;
}
void del(int val) {
sum -= val;
for (int i = val; i <= lim; i++) {
dp1[i] -= dp1[i - val];
dp2[i] -= dp2[i - val];
dp3[i] -= dp3[i - val];
dp4[i] -= dp4[i - val];
}
}
int n;
int a[N];
int cnt[A];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
add(a[i]);
}
if (sum & 1 || !check(sum / 2)) {
cout << 0;
return 0;
}
lim = sum;
for (int i = 0; i < n; i++) {
if (i) add(a[i - 1]);
del(a[i]);
for (int s = 0; s <= lim; s++) {
if (check(s)) {
cnt[abs(2 * s - sum)]++;
}
}
}
vector<int> res;
for (int i = 1; i <= lim; i++) {
if (cnt[i] == 2 * n)
res.push_back(i);
}
cout << (int)res.size() << '\n';
for (int c : res) cout << c << ' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |