이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//In the name of God
#include <bits/stdc++.h>
#include "shortcut.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define lc (id << 1)
#define rc (lc | 1)
struct node{
ll mxr, mxl, mx;
node(){
mxr = mxl = mx = -1;
}
};
ll n, ps[maxn], d[maxn];
node seg[maxn << 2];
node mrg(node l, node r){
if(l.mx == -1) return r;
if(r.mx == -1) return l;
node nd;
nd.mx = max({l.mx, r.mx, l.mxl + r.mxr});
nd.mxl = max(l.mxl, r.mxl);
nd.mxr = max(l.mxr, r.mxr);
return nd;
}
void bld(ll id, ll s, ll e){
if(e - s == 1){
seg[id].mx = d[s];
seg[id].mxl = d[s] - ps[s];
seg[id].mxr = d[s] + ps[s];
return;
}
ll mid = (s + e) >> 1;
bld(lc, s, mid);
bld(rc, mid, e);
seg[id] = mrg(seg[lc], seg[rc]);
return;
}
node get(ll id, ll s, ll e, ll l, ll r){
if(r <= s || e <= l) return node();
if(l <= s && e <= r) return seg[id];
ll mid = (s + e) >> 1;
return mrg(get(lc, s, mid, l, r), get(rc, mid, e, l, r));
}
node get(ll l, ll r){
node nd;
nd.mx = d[l];
nd.mxl = d[l] - ps[l];
nd.mxr = d[l] + ps[l];
for(ll i = l + 1; i < r; i++){
nd.mx = max(nd.mx, nd.mxl + d[i] + ps[i]);
nd.mxl = max(nd.mxl, d[i] - ps[i]);
nd.mxr = max(nd.mxr, d[i] + ps[i]);
}
return nd;
return get(1, 0, n, l, r);
}
long long find_shortcut(int N, vector<int> l, vector<int> D, int c){
n = N;
for(ll i = 0; i < n; i++){
d[i] = D[i];
ps[i + 1] = ps[i] + l[i];
}
bld(1, 0, n);
ll ans = get(0, n).mx;
for(ll i = 0; i < n; i++){
for(ll j = i + 1; j < n; j++){
ll x = get(0, i + 1).mxl + get(j, n).mxr - max(0ll, (ps[j] - ps[i]) - c);
x = max(x, get(0, j).mx);
x = max(x, get(i + 1, n).mx);
ans = min(ans, x);
}
}
return ans;
}
/*int main(){
fast_io;
return 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... |