# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40905 | IvanC | Bali Sculptures (APIO15_sculpture) | C++14 | 1068 ms | 14840 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;
typedef long long ll;
const int MAXN = 102;
unordered_set<ll> dp[MAXN][MAXN];
int N,A,B;
ll soma[MAXN],best;
ll calc(int a,int b){return soma[b] - soma[a-1];}
void solve(int pos,int resta,ll curOr){
if(resta < 0) return;
if(dp[pos][resta].count(curOr)) return;
for(ll i = 0;(1LL <<i)<=curOr;i++){
if(curOr & (1LL << i)){
if(dp[pos][resta].count(curOr ^ (1LL << i))) return;
}
}
dp[pos][resta].insert(curOr);
if(pos == N + 1){
if(resta != 0) return;
best = min(best,curOr);
return;
}
if(resta == 0) return;
for(int quebra = pos;quebra<=N;quebra++){
solve(quebra+1,resta - 1,curOr | calc(pos,quebra));
}
}
int main(){
scanf("%d %d %d",&N,&A,&B);
for(int i = 1;i<=N;i++){
scanf("%lld",&soma[i]);
soma[i] += soma[i-1];
}
best = (ll)1e18;
for(int i = A;i<=B;i++) solve(1,i,0);
printf("%lld\n",best);
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... |