#include "shortcut.h"
#include <vector>
#include <iostream>
using namespace std;
using ll = long long;
using vll = vector<ll>;
const ll INF = 1'000'000'000'000'000'000LL;
ll find_shortcut(int n, vector<int> track_len, vector<int> d, int c)
{
vll x(n, 0);
for(int i = 1; i < n; i++) x[i] = x[i-1] + track_len[i-1];
ll lo = 1;
ll hi = 1'000'000'000'000'000'000LL;
vll y(n, 0);
for(int i = 0; i < n; i++) y[i] = d[i];
ll l = c;
while(lo != hi)
{
ll k = (lo+hi)/2;
ll sum_lo = -INF;
ll sum_hi = INF;
ll diff_lo = -INF;
ll diff_hi = INF;
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
if(y[i] + y[j] + x[j] - x[i] <= k) continue;
sum_lo = max(sum_lo, (x[i] + y[i]) + (x[j] + y[j]) + l - k + 1);
sum_hi = min(sum_hi, (x[i] - y[i]) + (x[j] - y[j]) + k - l);
diff_hi = min(diff_hi, -(x[i] + y[i]) + (x[j] - y[j]) + k - l);
diff_lo = max(diff_lo, -(x[i] - y[i]) + (x[j] + y[j]) + l - k);
}
}
bool works = 0;
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
if(sum_lo <= x[i] + x[j] && x[i] + x[j] <= sum_hi)
{
if(diff_lo <= x[j] - x[i] && x[j] - x[i] <= diff_hi)
{
works = 1;
}
}
}
}
if(works) hi = k;
else lo = k+1;
}
return lo;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
n = 4, incorrect answer: jury 80 vs contestant 81 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
n = 4, incorrect answer: jury 80 vs contestant 81 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
n = 4, incorrect answer: jury 80 vs contestant 81 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
n = 4, incorrect answer: jury 80 vs contestant 81 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
n = 4, incorrect answer: jury 80 vs contestant 81 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
n = 4, incorrect answer: jury 80 vs contestant 81 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
n = 4, incorrect answer: jury 80 vs contestant 81 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
n = 4, incorrect answer: jury 80 vs contestant 81 |
2 |
Halted |
0 ms |
0 KB |
- |