#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define int long long
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pb push_back
#define sp <<" "<<
#define cont(x) for(auto el:x) cout<<el<<' ';cout<<endl;
#define contp(x) for(auto el:x) cout<<el.fi<<'-'<<el.se<<' ';cout<<endl;
#define DEBUG(x) cout<<#x sp x<<endl;
#define carp(x,y) ((x%MOD)*(y%MOD))%MOD
#define topla(x,y) ((x%MOD)+(y%MOD))%MOD
#define mid (l+r)/2
const int MAXN=2e3+5;
const int MOD=1e9+7;
const int INF=1e18;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,a,b;
cin>>n>>a>>b;
vi ar(n+1);
FORE(i,1,n+1) cin>>ar[i];
vi pref(n+1,0);
FORE(i,1,n+1) pref[i]=pref[i-1]+ar[i];
if(a==1){
vi dp(n+1); //dp[i] --> i.pozisyondaki current prefimi valid kılan
//min grup sayısı
int curpref=(1LL<<60)-1;
for(int bt=59;bt>=0;bt--){ //is it possible to make bt 0
dp[0]=0;
FORE(i,1,n+1) dp[i]=INF;
FORE(i,1,n+1){
FORE(j,1,i+1){
int deg=pref[i]-pref[j-1];
if(dp[j-1]==INF) continue;
if((deg&curpref)!=deg) continue; //deg curprefin subseti mi
if(!(deg&(1LL<<bt))){
dp[i]=min(dp[i],dp[j-1]+1);
}
}
}
if(a<=dp[n] and dp[n]<=b) curpref-=(1LL<<bt);
}
cout<<curpref<<endl;
}
else{
vector<vb> dp(n+1,vb(n+1,false));
int curpref=(1LL<<60)-1;
for(int bt=59;bt>=0;bt--){ //is it possible to make bt 0
FOR(i,n+1){
FOR(k,b+1){
dp[i][k]=false;
}
}
dp[0][0]=true;
FORE(i,1,n+1){
FORE(j,1,i+1){
int deg=pref[i]-pref[j-1];
if((deg&curpref)!=deg) continue;
if(deg&(1LL<<bt)) continue;
FOR(k,b){
if(!dp[j-1][k]) continue;
dp[i][k+1]=true;
}
}
}
bool f=false;
FORE(i,a,b+1){
if(dp[n][i]){
curpref-=(1LL<<bt);
f=true;
break;
}
}
}
cout<<curpref<<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... |