이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shortcut.h"
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; i--)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
ll find_shortcut(int n, vi l, vi d, int c) {
vl L(n);
rep(i, n - 1) L[i + 1] = L[i] + l[i];
ll ok = linf, ng = 0;
auto f = [&](ll x) -> bool {
bool first = true;
ll p, q, r, s;
rep(a, n) rep2(b, a + 1, n) {
ll nx = x - d[a] - d[b];
if (L[b] - L[a] <= nx) continue;
if (c > nx) return false;
ll w = nx - c;
ll np = L[a] + L[b] - w;
ll nq = L[a] + L[b] + w;
ll nr = -L[a] + L[b] - w;
ll ns = -L[a] + L[b] + w;
if (first) {
p = np;
q = nq;
r = nr;
s = ns;
first = false;
} else {
chmax(p, np);
chmin(q, nq);
chmax(r, nr);
chmin(s, ns);
}
}
if (first) return true;
rep(i, n) rep2(j, i + 1, n) {
ll nx = L[i] + L[j];
ll ny = -L[i] + L[j];
if (p <= nx and nx <= q and r <= ny and ny <= s) return true;
}
return false;
};
while (ok - ng > 1) {
ll mid = (ok + ng) / 2;
(f(mid) ? ok : ng) = mid;
}
return ok;
}
# | 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... |