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;
#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
ll n,a,b;
vi y;
bool possible(ll forbiddenBits){
//cout<<forbiddenBits<<": "<<endl;
vector<vector<bool> > dp(n+1,vector<bool>(n+1,false)); //dp[numGroups][index];
rep(i,a,b+1) dp[i][n] = true;
for(ll i = n-1;i>=0;--i){
rep(numGroups,0,n){
ll sum = 0;
rep(j,i+1,n+1){
sum += y[j-1];
dp[numGroups][i] = (dp[numGroups][i]|(((sum&forbiddenBits)==0)&&(dp[numGroups+1][j])));
}
//cout<<dp[numGroups][i];
}
// cout<<endl;
}
return dp[0][0];
}
int main(){
cin.sync_with_stdio(false);
cin>>n>>a>>b;
y.resize(n);
rep(i,0,n) cin>>y[i];
ll ans = 0;
ll forbiddenBits = 0;
for(ll i = 60; i>=0;--i){
forbiddenBits |= (1LL<<i);
if(!possible(forbiddenBits))
forbiddenBits ^= (1LL<<i);
//cout<<((forbiddenBits&(1LL<<i))>0);
if(!(forbiddenBits&(1LL<<i)))
ans |= (1LL<<i);
}
//cout<<endl;
cout<<ans<<endl;
//cout<<possible(2305843009213693942ll)<<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... |