Submission #925217

#TimeUsernameProblemLanguageResultExecution timeMemory
925217atomBootfall (IZhO17_bootfall)C++17
13 / 100
41 ms3676 KiB
#include "bits/stdc++.h" // @JASPER'S BOILERPLATE using namespace std; using ll = long long; #ifdef JASPER #include "debug.h" #else #define debug(...) 166 #endif const int N = 501 * 501; int n; int a[N]; signed main() { cin.tie(0) -> sync_with_stdio(0); #ifdef JASPER freopen("in1", "r", stdin); #endif cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; int sz = accumulate(a + 1, a + 1 + n, 0); // dp(x) : number of ways constructing sum equal to x; vector <int> dp1(N, 0), dp2(N, 0), able(N, 1); dp1[0] = 1; // solving first case: a[0] is the observer // -> use first case to solve others for (int i = 1; i <= n; ++i) for (int j = sz; j >= a[i]; --j) dp1[j] += dp1[j - a[i]]; if ((sz & 1) || !dp1[sz / 2]) { cout << "0\n"; return 0; } auto solve = [&] (int id) -> void { for (int i = 0; i < N; ++i) dp2[i] = dp1[i]; for (int j = a[id]; j < N; ++j) dp2[j] -= dp2[j - a[id]]; // choose value for (int x = 1; x < N; ++x) { int new_sz = sz - a[id] + x; if ((new_sz & 1) || (new_sz / 2 < x) || dp2[(new_sz / 2) - x] <= 0) able[x] = 0; } }; for (int i = 1; i <= n; ++i) { // debug(able[3]); solve(i); } vector <int> ans; for (int x = 1; x < N; ++x) { if (able[x]) { ans.push_back(x); } } cout << (int) (ans.size()) << "\n"; for (int x : ans) cout << x << " "; }
#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...