Submission #131299

#TimeUsernameProblemLanguageResultExecution timeMemory
131299mlyean00Bali Sculptures (APIO15_sculpture)C++14
100 / 100
122 ms508 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, a, b; cin >> n >> a >> b; vector<ll> y(n); for (int i = 0; i < n; ++i) { cin >> y[i]; } vector<ll> pref(n + 1, 0); partial_sum(y.begin(), y.end(), pref.begin() + 1); ll ans = 0; if (a == 1) { for (int bit = 40; bit >= 0; --bit) { int dp[n + 1]; dp[0] = 0; fill(dp + 1, dp + n + 1, INT_MAX); ll b1 = ans >> bit; for (int i = 0; i <= n; ++i) { if (dp[i] == INT_MAX) continue; for (int j = i + 1; j <= n; ++j) { ll b2 = (pref[j] - pref[i]) >> bit; if ((b1 | b2) != b1) continue; dp[j] = min(dp[j], dp[i] + 1); } } if (dp[n] > b) ans |= 1LL << bit; } } else { for (int bit = 40; bit >= 0; --bit) { bool dp[b + 1][n + 1]; memset(dp, 0, sizeof(dp)); dp[0][0] = true; ll b1 = ans >> bit; bool p = false; for (int i = 0; i < b; ++i) { for (int j = 0; j <= n; ++j) { if (!dp[i][j]) continue; for (int k = j + 1; k <= n; ++k) { ll b2 = (pref[k] - pref[j]) >> bit; dp[i + 1][k] |= (b1 | b2) == b1; } } if (i + 1 >= a && dp[i + 1][n]) p = true; } if (!p) ans |= 1LL << bit; } } cout << ans << endl; 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...