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;
typedef long long ll;
const int mx = 2005;
int n, A, B;
ll S[mx], ans;
bool dp1[105][105];
void solve1(){
ans = 0;
ll cur = 0;
for(int b = 41; b >= 0; b--){
ll t = cur | (1LL << b);
dp1[0][0] = true;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= i; j++){
dp1[i][j] = false;
for(int k = 0; k < i; k++){
ll ps = S[i] - S[k];
if(!(ps & t)){
dp1[i][j] |= dp1[k][j-1];
}
}
}
}
bool able = false;
for(int i = A; i <= B; i++){
able |= dp1[n][i];
}
if(able){
cur = t;
}else{
ans |= (1LL << b);
}
}
}
int dp2[mx];
void solve2(){
ans = 0;
ll cur = 0;
for(int b = 41; b >= 0; b--){
ll t = cur | (1LL << b);
for(int i = 1; i <= n; i++){
dp2[i] = INT_MAX;
for(int j = 0; j < i; j++){
ll ps = S[i] - S[j];
if(!(ps & t)){
dp2[i] = min(dp2[i], dp2[j] + 1);
}
}
}
if(dp2[n] <= B){
cur = t;
}else{
ans |= (1LL << b);
}
}
}
void input(){
cin >> n >> A >> B;
for(int i = 1; i <= n; i++){
cin >> S[i];
S[i] += S[i-1];
}
}
int main(){
input();
n <= 100 ? solve1() : solve2();
cout << ans << endl;
return 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... |