#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)
{
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;
ll rightside;
for (int i = 0; i < n; i++){
for (int j = i+1; j < n; j++){
if (j>=r){
rightside=max(rightside,min(query(i,j),query(i,l)+query(j,r)+c)+(ll)d[i]+(ll)d[j]);
}
else {
leftside=max(rightside,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;
}
Compilation message
shortcut.cpp: In static member function 'static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = void; _Functor = find_shortcut(int, std::vector<int>, std::vector<int>, int)::<lambda(int, int)>; _ArgTypes = {int, int}]':
shortcut.cpp:24:12: warning: 'rightside' may be used uninitialized in this function [-Wmaybe-uninitialized]
24 | ll rightside;
| ^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
n = 4, incorrect answer: jury 80 vs contestant 9223372036854775807 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
n = 4, incorrect answer: jury 80 vs contestant 9223372036854775807 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
n = 4, incorrect answer: jury 80 vs contestant 9223372036854775807 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
n = 4, incorrect answer: jury 80 vs contestant 9223372036854775807 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
n = 4, incorrect answer: jury 80 vs contestant 9223372036854775807 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
n = 4, incorrect answer: jury 80 vs contestant 9223372036854775807 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
n = 4, incorrect answer: jury 80 vs contestant 9223372036854775807 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
n = 4, incorrect answer: jury 80 vs contestant 9223372036854775807 |
2 |
Halted |
0 ms |
0 KB |
- |