# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
996237 | Baytoro | Bali Sculptures (APIO15_sculpture) | C++17 | 1 ms | 348 KiB |
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 fr first
#define sc second
#define pb push_back
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
#define ll long long
const int N=3e4+5;
int n,a,b;
const int INF=1e12;
int y[N];
bool check(int x){
if(a==1){
vector<int> dp(n+1,INF);
dp[0]=0;
for(int i=0;i<n;i++){
int sum=0;
for(int j=i+1;j<=n;j++){
sum+=y[j];
if((sum|x)==x){
dp[j]=min(dp[j],dp[i]+1);
}
}
}
return (dp[n]<=b);
}
vector<vector<int> > dp(n+1,vector<int>(n+1,0));
dp[0][0]=1;
for(int i=0;i<n;i++){
for(int j=0;j<b;j++){
int sum=0;
if(dp[i][j]){
for(int k=i+1;k<=n;k++){
sum+=y[k];
if((sum|x)==x)
dp[k][j+1]=dp[i][j];
}
}
}
}
int ans=0;
for(int i=a;i<=b;i++) ans|=(dp[n][i]);
return ans;
}
/*
6 1 3
8 1 2 1 5 4
*/
void solve(){
cin>>n>>a>>b;
for(int i=1;i<=n;i++) cin>>y[i];
int ans=(1<<35)-1;
for(int i=35;i>=0;i--){
if(check(ans-(1<<i))){
ans-=(1<<i);
}
}
cout<<ans<<endl;
}
signed main(){
//fopn("paint");
int t=1;//cin>>t;
while(t--) solve();
}
Compilation message (stderr)
# | 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... |