This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
const long long maxn=2000+10,lg=45;
long long n,l,r,all[maxn],mainres,ps[maxn];
void vorod(){
cin>>n>>l>>r;
for(long long i=1;i<=n;i++){
cin>>all[i];
}
}
long long check2(long long f){
vector<short>dp(n+1);
dp[0]=0;
for(long long i=1;i<=n;i++){
dp[i]=n+2;
for(long long j=i;j>=1;j--){
dp[i]=(dp[i]<dp[j]+1)||((ps[i]-ps[j-1])&f)?dp[i]:dp[j]+1;
}
}
return dp[n]<=r;
}
long long check1(long long f){
vector<vector<char>>dp(n+1,vector<char>(n+1));
dp[0][0]=1;
for(long long i=1;i<=n;i++){
for(int h=1;h<=r;h++){
long long suma=0;
for(int j=i;j>=1;j--){
suma+=all[j];
if(suma&f){
continue;
}
if(dp[j-1][h-1]){
dp[i][h]=1;
break;
}
}
}
}
for(long long i=l;i<=r;i++){
if(dp[n][i]==1){
return 1;
}
}
return 0;
}
void solve1(){
long long fix=0;
for(long long i=lg-1;i>=0;i--){
fix+=(1ll<<i);
if(!check1(fix)){
fix-=(1ll<<i);
}
}
mainres=(1ll<<lg)-1-fix;
}
void solve2(){
long long fix=0;
for(long long i=lg-1;i>=0;i--){
fix+=(1ll<<i);
if(!check2(fix)){
fix-=(1ll<<i);
}
}
mainres=(1ll<<lg)-1-fix;
}
void khor(){
cout<<mainres<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("inp.txt","r",stdin);
vorod();
for(int i=1;i<=n;i++){
ps[i]=all[i]+ps[i-1];
}
if(l>1){
solve1();
}else{
solve2();
}
khor();
}
# | 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... |