Submission #549135

#TimeUsernameProblemLanguageResultExecution timeMemory
549135Duy_eBali Sculptures (APIO15_sculpture)C++14
100 / 100
249 ms400 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<ll, ll> #define st first #define nd second #define file "test" using namespace std; const long long INF = 1e18; const long long N = 2e3 + 5; ll n, a[N], A, B, f[N], dp[N], dp2[N]; ll get(int l, int r) { return f[r] - f[l - 1]; } bool solve(ll x, ll pre) { int cnt = 1; ll sum = 0; for (int i = 0; i <= n; i ++) dp[i] = n + 1, dp2[i] = 0; dp[0] = 0; for (int i = 0; i <= n; i ++) { for (int j = i + 1; j <= n; j ++) if ((get(i + 1, j) | pre) <= x) { dp[j] = min(dp[j], dp[i] + 1); dp2[j] = max(dp2[j], dp2[i] + 1); } } return dp[n] <= B && dp2[n] >= A; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen(file".inp","r",stdin); freopen(file".out","w",stdout); // #endif cin >> n >> A >> B; for (int i = 1; i <= n; i ++) cin >> a[i], f[i] = f[i - 1] + a[i]; ll ans = 0; int last = 45; // for (int i = 0; i < 45; i ++) { // for (int j = 0; j < last; j ++) { // ll tmp = ans | ((1ll << (j + 1)) - 1); // if (solve(ans, ans)) {i = 60; break;}; // if (solve(tmp, ans)) { // last = j; // ans |= 1ll << j; // // cout << j << ' ' << ans << '\n'; // } // } // } for (int i = 44; i >= 0; i --) { ll tmp = ans | ((1ll << (i + 1)) - 1); if (solve(ans, ans)) break; // cout << tmp << ' ' << solve(tmp) if (solve(tmp, ans)) { last = i; // cout << i <<"="<< '\n'; if (i == 0) { ans |= 1; break; } } else { ans |= 1ll << last; last = 0; tmp = ans | ((1ll << (i + 1)) - 1); if (solve(ans, ans)) break; if (solve(tmp, ans)) { last = i; if (i == 0) { ans |= 1; break; } } } } // cout << solve(11, ans) << '\n'; cout << ans; return 0; } /** /\_/\ (= ._.) / >🍵 \>🍮 statement: given n number (n <= 100) a[i] <= 1e9 and two integer A, B; find the way to split the initial array into x consecutive subarray such that the sum of or of every subarray is minimum x should be any number between A, B -> A <= x <= B bitwise or operation OR minimum -> msb is lowest **/

Compilation message (stderr)

sculpture.cpp: In function 'bool solve(long long int, long long int)':
sculpture.cpp:18:6: warning: unused variable 'cnt' [-Wunused-variable]
   18 |  int cnt = 1;
      |      ^~~
sculpture.cpp:19:5: warning: unused variable 'sum' [-Wunused-variable]
   19 |  ll sum = 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...