Submission #108264

#TimeUsernameProblemLanguageResultExecution timeMemory
108264maksim_gaponovBali Sculptures (APIO15_sculpture)C++14
100 / 100
188 ms524 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define pb push_back const int INF = 1e18; void run() { int n, a, b; cin >> n >> a >> b; vector<int> y(n); for (auto &x : y) cin >> x; vector<int> pref(1, 0); for (auto x : y) pref.pb(pref.back() + x); if (a == 1) { int ans = (1ll << 61) - 1; for (int B = 60; B >= 0; --B) { ans ^= (1ll << B); vector<int> dp(n + 1, INF); dp[0] = 0; // for (int i = 0; i <= n; ++i) { // dp[0][i] = 1; // } for (int i = 1; i <= n; ++i) { for (int k = 0; k < i; ++k) { int sum = pref[i] - pref[k]; if (~ans & sum) { continue; } dp[i] = min(dp[i], dp[k] + 1); } } bool can = (dp[n] <= b); if (!can) { ans ^= (1ll << B); } } cout << ans << '\n'; } else { int ans = (1ll << 61) - 1; for (int B = 60; B >= 0; --B) { ans ^= (1ll << B); vector<vector<int>> dp(n + 1, vector<int>(n + 1)); dp[0][0] = 1; // for (int i = 0; i <= n; ++i) { // dp[0][i] = 1; // } for (int j = 1; j <= n; ++j) { for (int i = 1; i <= n; ++i) { for (int k = 0; k < i; ++k) { if (!dp[j - 1][k]) continue; int sum = pref[i] - pref[k]; if (~ans & sum) { continue; } dp[j][i] = 1; break; } } } bool can = 0; for (int i = a; i <= b; ++i) { if (dp[i][n]) can = 1; } if (!can) { ans ^= (1ll << B); } } cout << ans << '\n'; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); run(); }
#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...