# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
185655 | dndhk | Bali Sculptures (APIO15_sculpture) | C++14 | 324 ms | 11128 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>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 2000;
const int INF = 10000000;
int N, A, B;
vector<ll> v;
ll sum[MAX_N+1];
ll ans;
ll Sum(ll x, ll y){
return sum[max(x, y)] - sum[min(x, y)-1];
}
vector<int> gp[MAX_N+1];
bool chk1[MAX_N+1], chk2[MAX_N+1];
bool check(ll x){
for(int i=0; i<=N; i++){
while(!gp[i].empty()) gp[i].pop_back();
}
for(int i=1; i<=N; i++){
for(int j=i; j<=N; j++){
if((Sum(i, j) | x) == x){
gp[i-1].pb(j);
}
}
}
for(int i=0; i<=N; i++) chk1[i] = chk2[i] = false;
chk1[0] = true;
for(int t=1; t<=B; t++){
for(int i=0; i<=N; i++){
if(chk1[i]){
for(int j : gp[i]){
chk2[j] = true;
}
}
}
for(int i=0; i<=N; i++){
chk1[i] = chk2[i];
chk2[i] = false;
}
if(t>=A && chk1[N]) return true;
}
return false;
}
void solve1(){
ans = (1LL<<40LL)-1;
for(int k=39; k>=0; k--){
ll t = (1LL<<(ll)k);
if(check(ans-t)){
ans-=t;
}
}
}
deque<int> dq;
int dist[MAX_N+1];
bool check2(ll x){
for(int i=0; i<=N; i++){
while(!gp[i].empty()) gp[i].pop_back();
}
for(int i=1; i<=N; i++){
for(int j=i; j<=N; j++){
if((Sum(i, j) | x) == x){
gp[i-1].pb(j);
}
}
}
for(int i=0; i<=N; i++) dist[i] = INF;
dist[0] = 0;
dq.pb(0);
while(!dq.empty()){
int now = dq.front(); dq.pop_front();
for(int i : gp[now]){
if(dist[i]>dist[now]+1){
dist[i] = dist[now]+1;
dq.pb(i);
}
}
}
return (dist[N]<=B);
}
void solve2(){
ans = (1LL<<45LL)-1;
for(int k=44; k>=0; k--){
ll t = (1LL<<(ll)k);
if(check2(ans-t)){
ans-=t;
}
}
}
int main(){
scanf("%d%d%d", &N, &A, &B);
v.pb(0LL);
for(int i=1 ;i<=N; i++){
ll x; scanf("%lld", &x);
v.pb(x);
sum[i]=sum[i-1]+v[i];
}
if(A!=1) solve1();
else solve2();
cout<<ans;
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... |