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>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2100, LOG = 40, INF = 1e9;
ll ps[N], n, A, B;
bool dp[N][N];
int pd[N];
bool good(ll vl, int k, ll res){
if(((vl | res) - res) < (1LL << k))return true;
return false;
}
bool check(int k, ll res){
dp[0][0] = true;
for(int i=1; i<=n; i++)
dp[i][0] = false;
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
dp[i][j] = false;
for(int t=i-1; t>=0; t--)
if(good(ps[i] - ps[t], k, res))
dp[i][j] |= dp[t][j - 1];
}
}
for(int i=A; i<=B; i++)
if(dp[n][i])return true;
return false;
}
bool check2(int k, ll res){
pd[0] = 0;
for(int i=1; i<=n; i++){
pd[i] = INF;
for(int t=i-1; t>=0; t--)
if(good(ps[i] - ps[t], k, res))
pd[i] = min(pd[i], pd[t] + 1);
}
if(pd[n] <= B)return true;
return false;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> A >> B;
for(int i=0; i<n; i++){
int x; cin >> x;
ps[i + 1] = ps[i] + x;
}
ll res = 0;
for(int i=LOG-1; i>=0; i--){
if(n > 110){
if(!check(i, res))res += (1LL << i);
}else{
if(!check2(i, res))res += (1LL << i);
}
}
cout << res << endl;
}
# | 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... |