Submission #784964

#TimeUsernameProblemLanguageResultExecution timeMemory
784964vqpahmadBootfall (IZhO17_bootfall)C++14
100 / 100
396 ms5804 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ll long long #define pii pair<int,int> #define F first #define S second #define endl '\n' #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() const int mod = 1e9 + 7; const int N = 502 * 502; const ll inf = 1e18; int dp[N]; int ok[N]; int32_t main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i=0;i<n;i++){ cin >> a[i]; } sort(all(a));// useless :D dp[0]=1; for (int i=0;i<n;i++) for (int j=N-1;j>=a[i];j--) dp[j] += dp[j-a[i]]; int sum=0; for_each(all(a),[&](int x){ sum+=x;}); bool flag = (sum%2==0 && dp[sum/2]); if(!flag) return cout << 0, 0; for (int i=0;i<n;i++){ // I will remove a[i] sum -= a[i]; for (int j=a[i];j<N;j++) dp[j] -= dp[j-a[i]]; for (int j=0;j<N;j++) if (dp[j]&&2*j-sum >= 0) ok[2*j-sum]++; for (int j=N-1;j>=a[i];j--) dp[j] += dp[j-a[i]]; sum += a[i]; } vector<int> ans; for (int i=0;i<N;i++) if (ok[i]==n) ans.pb(i); cout << sz(ans) << endl; for (auto it : ans){ cout << it << ' '; } cout << endl; }
#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...