Submission #854064

#TimeUsernameProblemLanguageResultExecution timeMemory
854064The_SamuraiBootfall (IZhO17_bootfall)C++17
100 / 100
241 ms17616 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; const ll inf = 1e18; const int N = 250001, sq = 23; int main() { cin.tie(0)->sync_with_stdio(false); #ifdef sunnatov freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, sum = 0; cin >> n; vector<int> a(n); for (int &x: a) cin >> x; vector<bitset<N>> without(sq); bitset<N> bs; bs.set(0); for (int x: a) bs |= bs << x; for (int i = 0; i < sq; i++) { without[i].set(0); for (int j = 0; j < n; j++) { if (i * sq <= j and j < (i + 1) * sq) continue; without[i] |= without[i] << a[j]; } } vector<bitset<N>> without_2(n); for (int i = 0; i < n; i++) { sum += a[i]; without_2[i] = without[i / sq]; for (int j = i - i % sq; j < min(n, i - i % sq + sq); j++) { if (i == j) continue; without_2[i] |= without_2[i] << a[j]; } } vector<int> ans; for (int i = 1; i < N; i++) { if (sum % 2 or !bs[sum / 2]) continue; sum += i; bool ok = true; for (int j = 0; j < n and ok; j++) { sum -= a[j]; if (sum % 2 or !without_2[j][sum / 2]) ok = false; sum += a[j]; } sum -= i; if (ok) ans.emplace_back(i); } cout << 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...