이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 3e5 + 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;
}
void solve(int tc) {
int n, A, B;
cin >> n >> A >> B;
int a[n+1];
for(int i=1; i<=n; i++) cin >> a[i];
int ps[n+1];
ps[0] = 0;
for(int i=1; i<=n; i++) ps[i] = ps[i-1] + a[i];
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;
}
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);
}
}
| # | 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... |