Submission #586735

#TimeUsernameProblemLanguageResultExecution timeMemory
586735ShinBootfall (IZhO17_bootfall)C++14
0 / 100
1 ms324 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define all(x) x.begin(), x.end() using namespace std; template <class X, class Y> bool minimize(X &a, Y b) { if (a > b) return a = b, true; return false; } template <class X, class Y> bool maximize(X &a, Y b) { if (a < b) return a = b, true; return false; } const int N = 500 + 500 + 7; int n; int sum; int a[N]; int cnt[N]; void solve(int l, int r, bitset<N> &dp) { if (l == r) { for (int i = 0; i < N; i ++) { int cur = sum - a[l] - i * 2; if (cur >= 0) { cnt[cur] += dp[i]; } } return; } int mid = (l + r) >> 1; bitset<N> tmp = dp; for (int i = l; i <= mid; i ++) { tmp |= (tmp << a[i]); } solve(mid + 1, r, tmp); for (int i = mid + 1; i <= r; i ++) { dp |= (dp << a[i]); } solve(l, mid, dp); } signed main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i ++) { cin >> a[i]; } sum = accumulate(a + 1, a + n + 1, 0); bitset<N> dp; dp[0] = 1; for (int i = 1; i <= n; i ++) { dp |= (dp << a[i]); } if ((sum & 1) || !dp[sum / 2]) { return cout << 0, 0; } dp.reset(); dp[0] = 1; solve(1, n, dp); vector<int> res; for (int j = 0; j < N; j ++) { if (cnt[j] == n) { res.push_back(j); } } cout << (int) res.size() << '\n'; for (int x: res) { 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...