Submission #842710

#TimeUsernameProblemLanguageResultExecution timeMemory
842710zwezdinvBootfall (IZhO17_bootfall)C++17
100 / 100
334 ms3924 KiB
#include<bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n); for (auto& i : a) cin >> i; int sm = accumulate(all(a), 0); vector<uint64_t> dp(sm + 1, 0); dp[0] = 1; for (int i = 0; i < n; ++i) { for (int j = sm - a[i]; j >= 0; --j) { dp[j + a[i]] += dp[j]; } } if (sm & 1 || dp[sm / 2] == 0) { cout << "0\n"; return 0; } vector<int> ans(sm + 1, 0); for (int i = 1; i <= sm; ++i) ans[i] = 1; for (int i = 0; i < n; ++i) { for (int j = 0; j <= sm - a[i]; ++j) { dp[j + a[i]] -= dp[j]; } for (int k = 1; k <= sm; ++k) { if ((sm - a[i] + k) & 1) ans[k] = 0; int tar = (sm - a[i] + k) / 2; if ((tar <= sm && dp[tar]) || (0 <= tar - k && tar - k <= sm && dp[tar - k])) {} else ans[k] = 0; } for (int j = sm - a[i]; j >= 0; --j) { dp[j + a[i]] += dp[j]; } } cout << accumulate(all(ans), 0) << '\n'; for (int i = 1; i <= sm; ++i) { if (ans[i]) cout << i << ' '; } }
#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...