제출 #298347

#제출 시각아이디문제언어결과실행 시간메모리
298347shayan_pSky Walking (IOI19_walk)C++17
15 / 100
522 ms35704 KiB
#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 < 17 && it != st.begin(); w++)
		it--;
	    tmp[j] = INF;
	    for(int w = 0; w < 34 && (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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...