답안 #612743

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
612743 2022-07-29T22:59:08 Z morete Sky Walking (IOI19_walk) C++17
0 / 100
37 ms 28104 KB
#include "bits/stdc++.h"
#include "walk.h"
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<algorithm>

using namespace std;

#define pb push_back
#define snd second
#define fst first
#define pb push_back
typedef long long int ll;

const ll INF = 9e18;

vector<pair<ll, ll>> adj[1000000];
map<ll, ll> last, hgt;


long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
	last.clear();
	hgt.clear();

	int n, m;
	map<ll, ll> dst; // altura, custo vertical, barra horizontal
	map<ll, vector<ll>> com, fim;

	n = x.size();
	m = l.size();
	int k = 0;


	for (int i = 0; i < n; i++){
		hgt[k] = 0;
		last[x[i]] = k++;
	}


	vector<array<ll, 3>> event; // 0 segmento, 1 saida

	for(int i = 0; i < n; i++)
		event.push_back({h[i], 1, x[i]});

	for(int i = 0; i < m; i++)
		event.push_back({y[i], 0, i});

	sort(event.begin(), event.end());

	set<int> pos;
	for (int i = 0; i < n; i++)
		pos.insert(x[i]);

	for (auto e : event){
		if (e[1] == 1){ // sai
			pos.erase(e[2]);
		}
		else{
			auto it = pos.lower_bound(l[e[2]]);
			while (it != pos.end() and *it <= r[e[2]]){
				int lst = last[*it];
				int dst = e[0] - hgt[lst];

				adj[k].pb({lst, dst});
				adj[lst].pb({k, dst});

				hgt[k] = e[0];
				last[*it] = k++;

				it++;
			}
		}
	}

	vector<ll> dist(k, -1);

	priority_queue<pair<ll,ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
	pq.push({0, s});

	while (!pq.empty()){
		ll v, d;
		tie(d, v) = pq.top();
		pq.pop();

		if (dist[v] == -1){
			dist[v] = d;
			for (auto x : adj[v])
				if (dist[x.fst] == -1)
					pq.push({d + x.snd, x.fst});
		}
	}

	return dist[g];
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 28104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 28104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -