Submission #50292

#TimeUsernameProblemLanguageResultExecution timeMemory
50292mra2322001Bootfall (IZhO17_bootfall)C++14
100 / 100
450 ms4588 KiB
#include <bits/stdc++.h> #define f0(i, n) for(int i=(0); i<n; i++) #define f1(i, n) for(int i=(1); i<=n; i++) using namespace std; typedef long long ll; const int N = 502; int n, a[N], f[N*N], tmp[N*N], sum = 0, dd[N*N]; void add(int x){ for(int i = sum; i >= 0; i--){ f[i] += f[i - x]; } } void del(int x){ for(int i = 0; i <= sum; i++) tmp[i] = f[i]; for(int i = 0; i <= sum; i++){ if(i >= x) tmp[i] -= tmp[i - x]; } } int main(){ ios_base::sync_with_stdio(0); cin >> n; f[0] = 1; f1(i, n){ cin >> a[i], sum += a[i]; add(a[i]); } if(sum%2 || f[sum/2]==0){ return cout << 0 << endl, 0; } f1(i, n){ del(a[i]); for(int j = sum; j >= 0; j--){ if(tmp[j] != 0){ int x = sum - 2*j - a[i]; if(x > 0) dd[x]++; } } } int cnt = 0; for(int j = 0; j <= sum; j++) if(dd[j]==n) ++cnt; cout << cnt << endl; for(int j = 0; j <= sum; j++) if(dd[j]==n) cout << j << " "; }
#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...