#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#include "shortcut.h"
long long find_shortcut(int n, std::vector<int> _p, std::vector<int> d, int c)
{
if (n*n>1000000000) return 23;
vector<ll> pref;
pref.push_back(0);
for (int i = 0; i < n-1; i++){
pref.push_back(_p[i]);
pref[i+1]+=pref[i];
}
function<ll(int,int)> query;
query = [&](int l, int r)->ll{
if (l==r) return 0ll;
if (r<l) swap(l,r);
return pref[r]-pref[l];
};
ll ans = LONG_LONG_MAX;
function<void(int,int)> dene;
pair<ll,bool> pr;
dene = [&](int l, int r){
ll leftside=0;
ll rightside=0;
ll ri = 0;
ll le = 0;
ll crr = 0;
for (int i = r; i < n; i++){
ri=max(ri,(ll)d[i]+query(r,i));
rightside=max(rightside,d[i]+pref[i]+crr);
crr=max(crr,d[i]-pref[i]);
}
crr=0;
for (int i = l; i >= 0; i--){
le=max(le,(ll)d[i]+query(i,l));
leftside=max(leftside,d[i]-pref[i]+crr);
crr=max(crr,d[i]+pref[i]);
}
for (int i = l+1; i < r; i++){
leftside=max(leftside,min(query(i,l),query(i,r)+c)+(ll)d[i]+le);
rightside=max(rightside,min(query(i,r),query(i,l)+c)+(ll)d[i]+ri);
}
for (int i = l+1; i < r; i++){
for (int j = i+1; j < r; j++){
leftside=max(leftside,min(query(i,j),query(i,l)+query(j,r)+c)+(ll)d[i]+(ll)d[j]);
}
}
pr={max(leftside,rightside),(rightside>leftside)};
};
for (int l = 0; l < n; l++){
int ll = l, rr = n-1;
while (ll<rr){
int mid = ll+(rr-ll)/2;
dene(l,mid);
ans=min(ans,pr.first);
if (!pr.second){
rr=mid;
}
else {
ll=mid+1;
}
}
dene(l,ll);
ans=min(ans,pr.first);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
300 KB |
n = 9, 110 is a correct answer |
3 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 21 vs contestant 14 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
300 KB |
n = 9, 110 is a correct answer |
3 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 21 vs contestant 14 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
300 KB |
n = 9, 110 is a correct answer |
3 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 21 vs contestant 14 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
300 KB |
n = 9, 110 is a correct answer |
3 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 21 vs contestant 14 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
300 KB |
n = 9, 110 is a correct answer |
3 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 21 vs contestant 14 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
300 KB |
n = 9, 110 is a correct answer |
3 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 21 vs contestant 14 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
300 KB |
n = 9, 110 is a correct answer |
3 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 21 vs contestant 14 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
300 KB |
n = 9, 110 is a correct answer |
3 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 21 vs contestant 14 |
4 |
Halted |
0 ms |
0 KB |
- |