Submission #507245

#TimeUsernameProblemLanguageResultExecution timeMemory
507245abc864197532Bootfall (IZhO17_bootfall)C++17
100 / 100
508 ms2044 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define eb emplace_back #define pb push_back #define X first #define Y second #define pii pair<int, int> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #define test(x...) abc("[" + string(#x) + "]", x); const int N = 500 * 500 + 5, C = 23; bitset <N> dp; int main () { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector <int> a(n); int sum = 0; dp.flip(0); for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; dp |= dp << a[i]; } if (sum & 1 || !dp[sum >> 1]) { cout << 0 << endl << endl; } else { vector <int> ans(N, 0); for (int i = 0; i < n; i += C) { int to = min(i + C, n); dp.reset(), dp.flip(0); for (int j = 0; j < i; ++j) dp |= dp << a[j]; for (int j = to; j < n; ++j) dp |= dp << a[j]; for (int j = i; j < to; ++j) { auto cur = dp; for (int k = i; k < to; ++k) if (k ^ j) cur |= cur << a[k]; for (int i = 0; i <= (sum - a[j]) / 2; ++i) if (cur[i]) ans[abs(sum - a[j] - i - i)]++; } } int cnt = 0; for (int i : ans) if (i == n) cnt++; cout << cnt << endl; for (int i = 0; i < N; ++i) if (ans[i] == n) cout << i << ' '; cout << endl; } }
#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...