이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define maxn 510
using namespace std;
int n, a[maxn], kS[maxn*maxn], isOk[maxn*maxn], ans, sum;
int main(){
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; ++i){
cin >> a[i];
sum += a[i];
}
kS[0] = 1;
for(int i = 0; i < n; ++i){
for(int j = sum-a[i]; j >= 0; --j){
kS[j+a[i]] += kS[j];
}
}if(sum%2 or !kS[sum/2]){
cout <<0;
return 0;
}
for(int i = 0; i < n; ++i){
int tmp = sum-a[i];
for(int j = a[i]; j <= sum; ++j){
kS[j] -= kS[j-a[i]];
//cerr << kS[j] << ' ';
if(2*j - tmp > 0 and kS[j]){
isOk[2*j - tmp]++;
if(isOk[-tmp+j*2] == n){
++ans;
}
}
}
for(int j = 1; j < a[i]; ++j){
if(2*j - tmp > 0 and kS[j]){
isOk[2*j - tmp]++;
if(isOk[-tmp+j*2] == n){
++ans;
}
}
}
cerr << '\n';
for(int j = sum-a[i]; j >= 0; --j){
kS[j+a[i]] += kS[j];
}
}
cout << ans << '\n';
for(int i = 1; i <= sum; ++i){
if(isOk[i] == n){
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... |