Submission #549125

#TimeUsernameProblemLanguageResultExecution timeMemory
549125Duy_eBali Sculptures (APIO15_sculpture)C++14
21 / 100
1089 ms348 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]; 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; 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); } // for (int i = 1; i <= n; i ++) { // sum += a[i]; // if ((sum | pre) > x) { // sum = a[i]; // cnt ++; // if ((sum | pre) > x) return false; // } // } return dp[n] <= B; } 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'; } } } 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...