Submission #1037533

#TimeUsernameProblemLanguageResultExecution timeMemory
1037533ByeWorldBootfall (IZhO17_bootfall)C++14
0 / 100
1 ms2396 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define int long long #define ll long long #define pb push_back #define fi first #define se second #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) using namespace std; typedef pair<int,int> pii; typedef pair<int,pii> ipii; const int MAXN = 505; const int MAXA = 250100; const int MAXK = 1e5+10; const int INF = 1e18+10; void chmn(int &a, int b){ a = min(a, b); } int n; int a[MAXN], sum; vector <int> ans; int dp[MAXA], can[MAXA]; signed main(){ // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i=1; i<=n; i++){ cin >> a[i]; sum += a[i]; } dp[0] = 1; for(int i=1; i<=n; i++){ for(int j=sum; j>=a[i]; j--){ dp[j] += dp[j-a[i]]; } } if(sum%2==1 || !dp[sum/2]){ cout << "0\n"; exit(0); } for(int i=1; i<=n; i++){ for(int j=a[i]; j<=sum; j++){ dp[j] -= dp[j-a[i]]; } for(int x=1; x<=sum; x++){ int num = sum+x-a[i]; if(num%2==0 && dp[num/2]) can[x]++; } for(int j=a[i]; j<=sum; j++){ dp[j] += dp[j-a[i]]; } } for(int i=1; i<=sum; i++) if(can[i]==n) ans.pb(i); cout << ans.size() << '\n'; for(auto in : ans) cout << in << ' '; cout << '\n'; }
#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...