Submission #930764

#TimeUsernameProblemLanguageResultExecution timeMemory
930764allin27xBootfall (IZhO17_bootfall)C++17
100 / 100
287 ms9284 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...