This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 502;
const int MAXV = MAXN*MAXN;
int g[MAXV];
int ar[MAXN];
int n;
int kp[MAXV];
int tp[MAXV];
void knap(int ind){
for (int i=0; i<MAXV; i++) tp[i] = kp[i];
int s = 0; for (int i=0; i<n; i++) if (i!=ind) s+= ar[i];
for (int i=0; i<MAXV - ar[ind] - 1; i++){
tp[i + ar[ind]] -= tp[i];
}
for (int i=0; i<MAXV; i++){
if (tp[i]){
if (2*i-s<=0) continue;
g[2*i-s] ++;
}
}
}
// new = old + (old<<a[i]);
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;
for (int i=0; i<n; i++) cin>>ar[i];
if (n&1) {cout<<0; exit(0);}
int s=0; for (int i=0; i<n; i++) s += ar[i];
kp[0] = 1;
for (int ind=0; ind<n; ind++){
for (int i=MAXV-ar[ind] - 1; i>=0; i--){
kp[i+ar[ind]] += kp[i];
}
}
if (!kp[s/2]) {cout<<0; exit(0);}
for (int i=0; i<n; i++){
knap(i);
}
set<int> good;
for (int i=1; i<MAXV; i++) if (g[i] == n) good.insert(i);
cout<<good.size()<<'\n';
for (int x: good) cout<<x<<' ';
}
# | 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... |