Submission #726425

#TimeUsernameProblemLanguageResultExecution timeMemory
726425stevancvBootfall (IZhO17_bootfall)C++14
100 / 100
981 ms4520 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 500 + 2; const int mod = 1e9 + 7; int a[N], cnt[N * N], dp92[N * N], dpc[N * N]; int Add(int a, int b) { a += b; while (a >= mod) a -= mod; while (a < 0) a += mod; return a; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int sum = 0; dp92[0] = 1; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; for (int j = sum; j >= a[i]; j--) { dp92[j] = Add(dp92[j], dp92[j - a[i]]); } } if (sum % 2 == 1 || dp92[sum / 2] == 0) { cout << 0 << en; return 0; } for (int i = 1; i <= n; i++) { for (int j = 0; j < a[i]; j++) dpc[j] = dp92[j]; for (int j = a[i]; j <= sum; j++) dpc[j] = Add(dp92[j], -dpc[j - a[i]]); for (int j = 0; j <= sum; j++) { int x = 2 * j + a[i] - sum; if (dpc[j] > 0 && x > 0) cnt[x] += 1; } } vector<int> ans; for (int i = 1; i <= sum; i++) if (cnt[i] == n) ans.push_back(i); cout << ans.size() << en; for (int i : ans) cout << i << sp; cout << en; 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...