이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#include "shortcut.h"
//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
using namespace std;
constexpr static int MXN = 1e6 + 5;
constexpr static int INF = 1e18;
int pf[MXN];
array<int, 2> jv[MXN];
array<int, 2> iv[MXN];
vector<int> d, l;
int c, n;
static inline int dist(int a, int b)
{
return pf[max(a, b)] - pf[min(a, b)];
}
vector<int> order;
bool check(int k)
{
int xl = -INF, xr = INF, yl = -INF, yr = INF;
int j = n;
/*
for (int i = n-1; i >= 0; i--)
{
while (j > 0 && jv[j-1][0] > k - iv[i][0]) j--;
if (j == n)
continue;
xl = max(xl, pf[i] + d[i] - k + jv[n-1][0] + c); // Always the biggest
xr = min(xr, pf[i] - d[i] + k - jv[j][1] - c);
yl = max(yl, -pf[i] + d[i] - k + jv[n-1][0] + c);
yr = min(yr, -pf[i] - d[i] + k - jv[j][1] - c);
}
*/
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++)
{
if (dist(i, j) + d[i] + d[j] > k)
{
xl = max(xl, pf[j] + pf[i] - k + c + d[i] + d[j]);
xr = min(xr, pf[j] + pf[i] + k - c - d[i] - d[j]);
yl = max(yl, pf[j] - pf[i] - k + c + d[i] + d[j]);
yr = min(yr, pf[j] - pf[i] + k - c - d[i] - d[j]);
}
}
}
xr++, yr++;
if (xr <= xl || yr <= yl)
return false;
debug(xl, xr, yl, yr);
int xs = n, xe = n, ys = 1, ye = 1;
for (int i = 0; i < n; i++)
{
while (xs > 0 && pf[xs-1] + pf[i] >= xl) xs--;
while (xe > 0 && pf[xe-1] + pf[i] >= xr) xe--;
while (ys < n && pf[ys] - pf[i] < yl) ys++;
while (ye < n && pf[ye] - pf[i] < yr) ye++;
if (max(xs, ys) < min(xe, ye))
{
debug(k, i, xs, xe, ys, ye);
return true;
}
}
return false;
}
long long find_shortcut(int32_t _n, vector<int32_t> _l, vector<int32_t> _d, int32_t _c)
{
c = _c;
n = _n;
for (int i : _l)
l.pb(i);
for (int i : _d)
d.pb(i);
array<int, 3> v = {0, 0, 0};
for (int i = 1; i <= n; i++)
pf[i] = pf[i-1] + l[i-1];
//int ll = v[1] + v[2] + c - 1, rr = INF;
for (int j = 0; j < n; j++)
jv[j] = {pf[j] + d[j], d[j] - pf[j]};
sort(jv, jv + n);
for (int j = n-2; j >= 0; j--)
jv[j][1] = max(jv[j][1], jv[j+1][1]);
for (int i = 0; i < n; i++)
iv[i] = {pf[i] + d[i], i};
sort(iv, iv + n);
int ll = 0, rr = INF;
while (rr - ll > 1)
{
int m = ll+rr>>1;
if (check(m))
rr = m;
else
ll = m;
}
return rr;
}
컴파일 시 표준 에러 (stderr) 메시지
shortcut.cpp: In function 'bool check(int64_t)':
shortcut.cpp:32:6: warning: unused variable 'j' [-Wunused-variable]
32 | int j = n;
| ^
shortcut.cpp: In function 'long long int find_shortcut(int32_t, std::vector<int>, std::vector<int>, int32_t)':
shortcut.cpp:104:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
104 | int m = ll+rr>>1;
| ~~^~~
shortcut.cpp:88:16: warning: unused variable 'v' [-Wunused-variable]
88 | array<int, 3> v = {0, 0, 0};
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |