#include<bits/stdc++.h>
using namespace std;
//#include "shortcut.h"
vector<int> l;
vector<int> d;
#define MAX 1000002
long long int pref[MAX];
long long int bc[MAX];
long long int c;
int n;
long long int dp[MAX];
void init(){
for(int i=0;i<d.size();i++){
if(i)pref[i]=pref[i-1]+l[i-1];
pref[i]=max(pref[i],(long long int)d[i]);
}
for(int i=d.size()-1;i>=0;i--){
if(i!=d.size()-1){
bc[i]=bc[i+1]+l[i];
}
bc[i]=max(bc[i],(long long int)d[i]);
}
}
int pref_id(long long int z){
return lower_bound(pref,pref+n,z)-pref;
}
int bc_id(long long int z){
return lower_bound(bc,bc+n,z,greater<long long int>() )-bc;
}
bool ok(long long int cost){
for(int i=0;i<n;i++){
if(pref[i]>cost)break;
for(int j=n-1;j>=i;j--){
if(bc[i]>cost)break;
if(max(i,pref_id(cost-pref[i]))>=min(j+1,bc_id(cost-pref[i]-c))-1){
if(max(i-1,pref_id(cost-pref[i]-c))+1>=min(i+1,bc_id(cost-pref[i]))){
return true;
}
}
}
}
return false;
}
long long find_shortcut(int n2, std::vector<int> l2, std::vector<int> d2, int c2)
{
n=d2.size();
c=c2;
l=l2;
d=d2;
n=d2.size();
init();
long long int mint=0;
long long int maxt=111111111111LL;
while(mint+1LL<maxt){
long long int mid=(mint+maxt)/2LL;
if(ok(mid)){
maxt=mid;
}
else{
mint=mid;
}
}
if(ok(mint))return mint;
return maxt;
}
Compilation message
shortcut.cpp: In function 'void init()':
shortcut.cpp:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<d.size();i++){
~^~~~~~~~~
shortcut.cpp:25:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i!=d.size()-1){
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |