Submission #969880

#TimeUsernameProblemLanguageResultExecution timeMemory
969880starchanBootfall (IZhO17_bootfall)C++17
65 / 100
1071 ms7200 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define in array<int, 2> #define pb push_back #define pob pop_back #define INF (int)1e17 #define fast() ios_base::sync_with_stdio(false); cin.tie(NULL) const int mod = 1e9+33; const int SMX = 2e5+5e4+10; const int MX = 5e5+10; int dp[MX]; void add(int x) { for(int i = MX-1; i >= x; i--) { dp[i]+=dp[i-x]; dp[i]%=mod; } return; } void rem(int x) { for(int i = x; i < MX; i++) { dp[i]-=dp[i-x]; dp[i]+=mod; dp[i]%=mod; } return; } int cnt[SMX]; signed main() { fast(); dp[0] = 1; int n; cin >> n; int S = 0; vector<int> a(n+1); for(int i = 1; i <= n; i++) { cin >> a[i]; S+=a[i]; add(a[i]); } if(S%2 || (dp[S/2] == 0)) { cout << "0\n"; return 0; } for(int i = 1; i <= n; i++) { rem(a[i]); for(int V = 0; V < SMX; V++) { int D = S+V-a[i]; if(D%2) continue; if(dp[(D/2)] || ((D >= 2*V) && ((dp[(D/2)-V])))) cnt[V]++; } add(a[i]); } vector<int> v; for(int i = 0; i < SMX; i++) { if(cnt[i] == n) v.pb(i); } cout << v.size() << "\n"; for(int x: v) cout << x << " "; cout << "\n"; return 0; }
#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...