이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
int a[505], f[250005], g[250005], dd[250005], mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, c = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
c += a[i];
}
f[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= c; j++) {
g[j] = f[j];
f[j] = 0;
}
for (int j = 0; j <= c - a[i]; j++) {
if (g[j] != 0) {
f[j] += g[j];
f[j + a[i]] += g[j];
if (f[j] >= mod) f[j] -= mod;
}
}
}
if (c % 2 != 0 || f[c / 2] == 0) {
cout << 0;
return 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= c; j++) {
g[j] = f[j];
}
for (int j = a[i]; j <= c; j++) {
g[j] -= g[j - a[i]];
if (g[j] < 0) g[j] += mod;
}
int h = c - a[i];
for (int j = 0; j <= c; j++) {
if (h - j < 0 || h % 2 != j % 2 || g[(h - j) / 2] == 0) {
dd[j] = 1;
}
}
}
int res = 0;
for (int i = 0; i <= c; i++) {
if (dd[i] == 0) {
res++;
}
}
cout << res << '\n';
for (int i = 0; i <= c; i++) {
if (dd[i] == 0) {
cout << i << " ";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |