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;
int g[MAXN*MAXN];
int ar[MAXN];
int n;
bitset<MAXN * MAXN> kp;
void knap(int ind){
kp.reset();
kp.set(0);
int s =0; for (int i=0; i<n; i++) if (i!= ind) s+=ar[i];
for (int i=0; i<n; i++){
if (i==ind) continue;
kp |= kp<<ar[i];
}
for (int i=1; i<n*MAXN; i++){
if (!kp[i]) continue;
if (2*i-s <= 0) continue;
g[2*i-s] ++;
}
}
int main(){
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.set(0);
for (int i=0; i<n; i++){
kp |= kp << ar[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<MAXN*MAXN; 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... |