Submission #50291

#TimeUsernameProblemLanguageResultExecution timeMemory
50291mra2322001Bootfall (IZhO17_bootfall)C++14
0 / 100
2 ms376 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], 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++){ if(i >= x) f[i] -= f[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, 0; } f1(i, n){ del(a[i]); for(int j = sum; j >= 0; j--){ if(f[j] != 0){ int x = sum - 2*j - a[i]; if(x > 0) dd[x]++; } } add(a[i]); } 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...