#include "shortcut.h"
#include <bits/stdc++.h>
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
inline void upmin(ll &a, ll b) { if(b < a) a = b; }
inline void upmax(ll &a, ll b) { if(a < b) a = b; }
const int MAXN = 1000055;
ll Mx[MAXN], Mn[MAXN];
ll X[MAXN], L[MAXN];
int O[MAXN];
int N; ll K;
bool isp(ll Y) {
ll xymx = -INFLL, xymn = INFLL, yxmx = -INFLL, yxmn = INFLL;
fill(Mx, Mx+N, -INFLL);
fill(Mn, Mn+N, INFLL);
for(int i = 0; i < N; i++) for(int j = i+1; j < N; j++) {
if(L[i]-X[i] <= Y-X[j]-L[j]) continue;
upmax(xymn, Y-K + X[i]-L[i] + X[j]-L[j]);
upmax(xymx, K-Y + X[i]+L[i] + X[j]+L[j]);
upmin(yxmn, Y-K + X[j]-L[j] - (X[i]+L[i]));
upmax(yxmx, K-Y + X[j]+L[j] - (X[i]-L[i]));
}
/*
for(int oi = 0, i, j = 1; j < N; j++) {
upmax(Mx[j], Mx[j-1]); upmin(Mn[j], Mn[j-1]);
for(ll t = Y-X[j]-L[j]; oi < N; oi++) {
i = O[oi];
if(L[i]-X[i] <= t) break;
upmax(Mx[max(i+1, j)], X[i]+L[i]);
upmin(Mn[max(i+1, j)], X[i]-L[i]);
}
upmin(xymn, Y-K + Mn[j] + X[j]-L[j]);
upmax(xymx, K-Y + Mx[j] + X[j]+L[j]);
upmin(yxmn, Y-K - Mx[j] + X[j]-L[j]);
upmax(yxmx, K-Y - Mn[j] + X[j]+L[j]);
}
*/
for(int s = 0; s < N; s++) for(int e = s+1; e < N; e++) {
if(X[s]+X[e] < xymx || xymn < X[s]+X[e]) continue;
if(X[e]-X[s] < yxmx || yxmn < X[e]-X[s]) continue;
return true;
}
for(int s = 0, xymxi = N-1, xymni = N-1, yxmxi = 0, yxmni = 0; s < N; s++) {
for(ll t = xymx-X[s]; xymxi && t <= X[xymxi-1]; xymxi--);
for(ll t = xymn-X[s]; 0 <= xymni && t < X[xymni]; xymni--);
for(ll t = yxmx+X[s]; yxmxi < N && X[yxmxi] < t; yxmxi++);
for(ll t = yxmn+X[s]; yxmni+1 < N && X[yxmni+1] <= t; yxmni++);
if(X[xymxi] < xymx-X[s] || yxmn+X[s] < X[yxmni]) continue;
if(max(xymxi, yxmxi) <= min(xymni, yxmni)) return true;
}
return false;
}
ll getAns() {
iota(O, O+N, 0); sort(O, O+N, [&](int a, int b) {
return L[a]-X[a] > L[b]-X[b];
});
ll s = 0, e = X[N-1] + *max_element(L, L+N)*2;
for(ll m; s < e;) {
m = (s+e) >> 1;
if(isp(m)) e = m;
else s = m+1;
}
return s;
}
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c) {
::N = n; ::K = c;
for(int i = 1; i < N; i++) ::X[i] = ::X[i-1] + l[i-1];
for(int i = 0; i < N; i++) ::L[i] = d[i];
return getAns();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
2 ms |
384 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
2 ms |
384 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
2 ms |
384 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
2 ms |
384 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
2 ms |
384 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
2 ms |
384 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
2 ms |
384 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
2 ms |
384 KB |
n = 3, incorrect answer: jury 29 vs contestant 20 |
8 |
Halted |
0 ms |
0 KB |
- |