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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}
void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
_print(H);
if(sizeof...(T)) cerr<<",";
else cerr<<"\"]";
dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxn=102;
bool dp[mxn][mxn];
ll sum[mxn];
ll val;
int n,a,b;
ll f(int l,int r) {
if(!l) return sum[r];
return sum[r]-sum[l-1];
}
bool ok(ll val) {
// can we partiton without any bit in val
memset(dp,false,sizeof(dp));
for(int i=0;i<n;i++) {
if((sum[i]&val)==0) dp[i][1]=true;
}
for(int i=1;i<n;i++) {
for(int g=2;g<=i+1;g++) {
for(int j=i-1;j>=0;j--) {
if(dp[j][g-1] and (f(j+1,i)&val)==0) {
dp[i][g]=true; break;
}
}
}
}
for(int i=a;i<=b;i++) {
if(dp[n-1][i]) return true;
}
return false;
}
int main () {
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>a>>b;
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) {
sum[i]=a[i];
if(i) sum[i]+=sum[i-1];
}
ll val=0;
for(int i=37;i>=0;i--) {
val+=(1LL<<i);
// debug(i,val,ok(val));
if(!ok(val)) val-=(1LL<<i);
}
// cout<<val<<endl;
cout<<(1LL<<38)-1-val<<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... |