이 제출은 이전 버전의 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)
#pragma GCC optimize("Ofast")
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;
set<int> tdo[maxn][2];
ll tmp[maxn];
map<pii, int> SE;
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< pair<int, ll> > st;
ll lazy = 0;
st.insert({0, 0});
tdo[0][1].insert(0);
for(int i = 0; i < m; i++){
SE[{l[i], y[i]}] = r[i];
tdo[l[i]][0].insert(y[i]);
if(r[i] != n-1)
tdo[r[i]][1].insert(y[i]);
}
for(int i = 0; i < n; i++){
int j = 0;
for(int H : tdo[i][0]){
auto it = st.lower_bound({H, -1});
for(int w = 0; w < 7 && it != st.begin(); w++)
it--;
tmp[j] = INF;
for(int w = 0; w < 14 && (it->F) <= h[i] && it != st.end(); w++, it++)
tmp[j] = min(tmp[j], (it->S) + abs(H - (it->F)));
j++;
}
for(int H : tdo[i][1]){
auto it = st.lower_bound({H, -1});
assert(it != st.end() && (it->F) == H);
st.erase(it);
}
j = 0;
for(int H : tdo[i][0]){
if(tmp[j] != INF){
st.insert({H, tmp[j]});
}
else{
assert(SE.count({i, H}));
tdo[SE[{i, H}]][1].erase(H);
}
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... |