Submission #211306

#TimeUsernameProblemLanguageResultExecution timeMemory
211306a14789654Bootfall (IZhO17_bootfall)C++17
100 / 100
367 ms3568 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 507; int D[maxn * maxn], a[maxn]; int main() { // freopen("TEST.INP", "r", stdin); // freopen("TEST.OUT", "w", stdout); int n, sum = 0; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i], sum += a[i]; D[0] = 1; for (int i = 1; i <= n; ++i) for (int j = sum / 2; j >= 0; --j) D[j + a[i]] += D[j]; if ((sum & 1) || !D[sum / 2]) return cout << 0, 0; vector <int> cnt(sum + 1); for (int i = 1; i <= n; ++i) { for (int j = 0; j <= sum; ++j) D[j + a[i]] -= D[j]; for (int j = 1; j <= sum; ++j) { int val = sum - a[i] + j; cnt[j] += (val / 2 - j >= 0 && 1 - val % 2 && D[val / 2 - j]); } for (int j = sum / 2; j >= 0; --j) D[j + a[i]] += D[j]; } vector <int> ans; for (int i = 1; i <= sum; ++i) if (cnt[i] == n) ans.push_back(i); cout << (int)ans.size() << '\n'; for (int x: ans) cout << x << ' '; 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...