This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1 % MOD;
int r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int fastlog(int x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
void solve(int tc) {
int n, a, b;
cin >> n >> a >> b;
int y[n+1];
for(int i=1; i<=n; i++) cin >> y[i];
int ps[n+1];
ps[0] = 0;
for(int i=1; i<=n; i++) ps[i] = ps[i-1] + y[i];
if(a!=1) {
int ans = 1e18;
for(int k=a; k<=b; k++) {
int msk = 0;
for(int bit=44; bit>=0; bit--) {
int dp[k+1][n+1];
for(int i=0; i<=k; i++) {
for(int j=0; j<=n; j++) {
dp[i][j] = 0;
}
}
for(int i=1; i<=n; i++) dp[1][i] = ((ps[i] & (msk + (1ll << bit))) == 0);
for(int i=2; i<=k; i++) {
for(int j=i; j<=n; j++) {
for(int l=i-1; l<j; l++) {
int wow = ps[j] - ps[l];
if((wow & (msk + (1ll << bit))) == 0) {
dp[i][j] |= dp[i-1][l];
}
}
}
}
if(dp[k][n]) {
msk += (1ll << bit);
}
}
ans = min(ans, (1ll << 45) - 1 - msk);
}
cout << ans << endl;
return;
}
int dp[n+1];
int ans = 0;
int forbid = 0;
for(int i=40; i>=0; i--) {
dp[0] = 0;
int newf = forbid | (1ll<<i);
for(int j=1; j<=n; j++) {
dp[j] = 1e18;
for(int k=0; k<j; k++) {
int cur = ps[j] - ps[k];
if((newf & cur) == 0) dp[j] = min(dp[j], dp[k] + 1);
}
}
if(dp[n] <= b) forbid |= (1ll<<i);
}
cout << (1ll<<41) - 1 - forbid << '\n';
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷
Compilation message (stderr)
sculpture.cpp: In function 'void solve(long long int)':
sculpture.cpp:64:7: warning: unused variable 'ans' [-Wunused-variable]
64 | int ans = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |