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;
using ll = long long;
const int maxn = (int)1e2+10;
const ll LINF = (ll)1e18;
int n, A, B;
ll a[maxn], pre[maxn]; ll ans=LINF;
bool needs(ll mask, int bit){
bool dp[110][110]; bool ok=1;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= B; j++)
dp[i][j]=false;
dp[0][0]=true;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= B; j++){
for(int k = 0; k<i; k++){
ll sum = pre[i]-pre[k]; bool skip=false;
for(int l = bit+1; l < 40; l++){
if(mask&(1ll<<l)) continue;
if(sum&(1ll<<l)) skip=true;
}
if(sum&(1ll<<bit) or skip) continue;
dp[i][j] |= dp[k][j-1];
}
}
}
for(int i = A; i <= B; i++) if(dp[n][i]) ok=0;
return ok;
}
bool needs2(ll mask, int bit){
int dp[2010];
for(int i = 0; i <= n; i++) dp[i]=n+1;
dp[0]=0;
for(int i = 1; i <= n; i++){
for(int k = 0; k<i; k++){
ll sum = pre[i]-pre[k]; bool skip=false;
for(int l = bit+1; l < 40; l++){
if(mask&(1ll<<l)) continue;
if(sum&(1ll<<l)) skip=true;
}
if(sum&(1ll<<bit) or skip) continue;
dp[i] = min(dp[i], dp[k]+1);
}
}
return dp[n]>B;
}
int32_t main() {
cin >> n >> A >> B; ans = 0;
for(int i = 0; i < n; i++) cin >> a[i], pre[i+1]=pre[i]+a[i];
for(int i = 40; i >= 0; i--)
ans|=(A>1?needs(ans|(1ll<<i),i):needs2(ans|(1ll<<i),i))*(1ll<<i);
cout << ans;
}
# | 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... |