# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21948 | mohammad_kilani | Bali Sculptures (APIO15_sculpture) | C++14 | 0 ms | 3024 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;
const int N = 101;
int n , a , b , arr[N];
bool dp[N][N][50];
bool vis[N][N][50];
bool cantake[N][N];
bool solve(int i,int j,int bit){
if(j > b)
return 0;
if(i == n){
if(j >= a && j <= b)
return 1;
return 0;
}
if(vis[i][j][bit])
return dp[i][j][bit];
vis[i][j][bit] = true;
long long sum = 0;
bool can = false;
for(int k=i;k<n;k++){
sum+=(long long)arr[k];
if(((sum >> (long long)bit)&1) == 0 && cantake[k+1][j+1] && solve(k+1,j+1,bit)){
can = true;
}
}
if(can){
sum =0 ;
for(int k=i;k<n;k++){
sum+=(long long)arr[k];
if(!(((sum >> bit)&1) == 0 && cantake[k+1][j+1] && solve(k+1,j+1,bit))){
cantake[k+1][j+1] = false;
}
}
}
dp[i][j][bit] = can;
return dp[i][j][bit];
}
int main(){
//freopen("in.txt","r",stdin);
memset(dp,-1,sizeof(dp));
memset(cantake,1,sizeof(cantake));
scanf("%d%d%d",&n,&a,&b);
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
long long ans = 0 ;
for(int i=46;i>=0;i--){
if(!solve(0,0,i)){
ans |= ((long long)1 << (long long)i);
}
}
cout << ans << endl;
return 0;
}
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... |