#include "shortcut.h"
#include "bits/stdc++.h"
#define ll long long
using namespace std;
//x+y, y-x (45 degrees rotation)
//|x-xx|+|y-yy| -> max(|x-xx|, |y-yy|)
const ll INF = 1e18;
vector<int> id;
int get_id(int x){
return 1 + int(lower_bound(id.begin(), id.end(), x) - id.begin());
}
bool check(ll k, vector<int> &d, int c, vector<ll>&p){
int n = d.size();
ll X = -INF, Y = -INF;
ll XX = INF, YY = INF;
for (int j = 0; j < n; j++){
int b = get_id(-d[j] - p[j]);
for (int i = 0; i < j; i++){
int a = get_id(d[i] - p[i] - k + 1);
if (a > b){
X = max(X, p[i] + p[j] - (k - c - d[i] - d[j]));
Y = max(Y, -p[i] + p[j] - (k - c - d[i] - d[j]));
XX = min(XX, p[i] + p[j] + (k - c - d[i] - d[j]));
YY = min(YY, -p[i] + p[j] + (k - c - d[i] - d[j]));
}
}
}
if (X > XX or Y > YY)
return 0;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++){
ll x = p[i] + p[j], y = p[j] - p[i];
if (X <= x and x <= XX and Y <= y and y <= YY)
return 1;
}
return 0;
}
ll find_shortcut(int n, vector<int> l, vector<int> d, int c){
vector<ll> p(n);
for (int i = 0; i < n-1; i++)
p[i+1] = p[i] + l[i];
for (int j = 0; j < n; j++)
id.push_back(- d[j] - p[j]);
sort(id.begin(), id.end());
id.erase(unique(id.begin(), id.end()), id.end());
ll st = 0, en = INF;
while (st < en){
ll mid = (st+en) >> 1;
if (check(mid, d, c, p))
en = mid;
else
st = mid + 1;
}
return st;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Incorrect |
0 ms |
212 KB |
n = 9, incorrect answer: jury 110 vs contestant 111 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Incorrect |
0 ms |
212 KB |
n = 9, incorrect answer: jury 110 vs contestant 111 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Incorrect |
0 ms |
212 KB |
n = 9, incorrect answer: jury 110 vs contestant 111 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Incorrect |
0 ms |
212 KB |
n = 9, incorrect answer: jury 110 vs contestant 111 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Incorrect |
0 ms |
212 KB |
n = 9, incorrect answer: jury 110 vs contestant 111 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Incorrect |
0 ms |
212 KB |
n = 9, incorrect answer: jury 110 vs contestant 111 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Incorrect |
0 ms |
212 KB |
n = 9, incorrect answer: jury 110 vs contestant 111 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Incorrect |
0 ms |
212 KB |
n = 9, incorrect answer: jury 110 vs contestant 111 |
3 |
Halted |
0 ms |
0 KB |
- |