이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "walk.h"
#define F first
#define S second
#define PB push_back
#define sz(s) (int(s.size()))
#define bit(n, k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 1e5 + 10;
const ll INF = 2e18;
vector<int> tdo[maxn][2];
ll tmp[maxn];
ll min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int src, int snk){
int n = sz(x), m = sz(y);
assert(src == 0 && snk == n-1);
set<pll> st;
ll lazy = 0;
st.insert({0, 0});
for(int i = 0; i < m; i++){
tdo[l[i]][0].PB(y[i]);
if(r[i] != n-1)
tdo[r[i]][1].PB(y[i]);
}
for(int i = 0; i < n; i++){
for(int j = 0; j < sz(tdo[i][0]); j++){
int H = tdo[i][0][j];
auto it = st.lower_bound({H, -1});
tmp[j] = INF;
if(it != st.end() && (it->F) <= h[i])
tmp[j] = min(tmp[j], (it->S) + abs(H - (it->F)));
if(it != st.begin())
it--, tmp[j] = min(tmp[j], (it->S) + abs(H - (it->F)));
}
for(int H : tdo[i][1]){
st.erase(st.lower_bound({H, -1}));
}
for(int j = 0; j < sz(tdo[i][0]); j++){
if(tmp[j] != INF)
st.insert({tdo[i][0][j], tmp[j]});
}
if(i > 0)
lazy+= x[i] - x[i-1];
}
auto it = st.begin();
if(st.empty())
return -1;
return lazy + (it->F) + (it->S);
}
# | 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... |