Submission #526078

#TimeUsernameProblemLanguageResultExecution timeMemory
526078TheKingAleksBootfall (IZhO17_bootfall)C++14
100 / 100
322 ms5892 KiB
#include<bits/stdc++.h> #define ll unsigned long long using namespace std; const ll MAX_N = 505; const ll MAX_N2 = 255025; ll sum,n,dp[MAX_N2],cnt[MAX_N2],a[MAX_N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(ll i=0; i<n; i++) { cin>>a[i]; sum+=a[i]; } dp[0] = 1; for(ll i=0; i<n; i++) { for(ll s=MAX_N2-a[i]-1; ; s--) { dp[s+a[i]] += dp[s]; if(s == 0) break; } } if(sum%2 != 0 || dp[sum/2] == 0) { cout<<0<<endl; return 0; } for(ll i=0; i<n; i++) /// ignore i-th { for(ll s=0; s+a[i]<MAX_N2; s++) { dp[s+a[i]] -= dp[s]; } sum-=a[i]; for(ll x0=1; x0<=sum; x0++) { if((sum+x0)%2 == 0) { if(dp[(sum+x0)/2] > 0) { cnt[x0]++; } } } sum+=a[i]; for(ll s=MAX_N2-a[i]-1; ;s--) { dp[s+a[i]] += dp[s]; if(s == 0) break; } } vector<ll> res; for(ll x0=1; x0<MAX_N2; x0++) { if(cnt[x0] == n) { res.push_back(x0); } } cout<<res.size()<<endl; for(auto x: res) 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...