답안 #592650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
592650 2022-07-09T12:06:07 Z Lucpp Sky Walking (IOI19_walk) C++17
24 / 100
4000 ms 220480 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int)(x).size())
typedef long long ll;
const ll INF = 1e18;

ll min_distance(vector<int> X, vector<int> H, vector<int> L, vector<int> R, vector<int> Y, int start, int goal) {
	int n = (int)X.size(), m = (int)L.size();
	vector<vector<int>> sect(n, {0});
	vector<vector<pair<int, int>>> goL(n, {{-1, -1}}), goR(n, {{-1, -1}});
	vector<tuple<int, int, int>> bridge;
	for(int i = 0; i < m; i++) bridge.emplace_back(Y[i], L[i], R[i]);
	sort(bridge.begin(), bridge.end());
	vector<pair<int, int>> tower;
	for(int i = 0; i < n; i++) tower.emplace_back(H[i], i);
	sort(tower.begin(), tower.end());
	set<int> active;
	for(int i = 0; i < n; i++) active.insert(i);
	int j = 0;
	for(auto [y, l, r] : bridge){
		while(j < n && tower[j].first < y) active.erase(tower[j++].second);
		auto it = active.find(l);
		int last = -1;
		while(it != active.end() && *it <= r){
			sect[*it].push_back(y);
			goL[*it].push_back({-1, -1});
			goR[*it].push_back({-1, -1});
			if(last != -1) goR[last].back() = {*it, sz(sect[*it])-1}, goL[*it].back() = {last, sz(sect[last])-1};
			last = *it;
			it++;
		}
	}
	map<pair<int, int>, ll> dist;
	priority_queue<tuple<ll, int, int>> pq;
	dist[make_pair(start, 0)] = 0;
	pq.emplace(0, start, 0);
	auto visit = [&](int x, int h, ll d){
		auto p = make_pair(x, h);
		if(!dist.count(p) || d < dist[p]){
			dist[p] = d;
			pq.emplace(-d, x, h);
		}
	};
	while(!pq.empty()){
		auto [d, x, h] = pq.top();
		pq.pop();
		d = -d;
		if(d > dist[make_pair(x, h)]) continue;
		if(goL[x][h].first != -1) visit(goL[x][h].first, goL[x][h].second, d+X[x]-X[goL[x][h].first]);
		if(goR[x][h].first != -1) visit(goR[x][h].first, goR[x][h].second, d+X[goR[x][h].first]-X[x]);
		if(h > 0) visit(x, h-1, d+sect[x][h]-sect[x][h-1]);
		if(h < sz(sect[x])-1) visit(x, h+1, d+sect[x][h+1]-sect[x][h]);
	}
	if(!dist.count(make_pair(goal, 0))) return -1;
	else return dist[make_pair(goal, 0)];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 300 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1502 ms 73480 KB Output is correct
4 Correct 1269 ms 97272 KB Output is correct
5 Correct 348 ms 42920 KB Output is correct
6 Correct 364 ms 40168 KB Output is correct
7 Correct 336 ms 42688 KB Output is correct
8 Correct 1865 ms 90280 KB Output is correct
9 Correct 488 ms 46284 KB Output is correct
10 Correct 1732 ms 122792 KB Output is correct
11 Correct 596 ms 48292 KB Output is correct
12 Correct 463 ms 50340 KB Output is correct
13 Correct 1440 ms 112484 KB Output is correct
14 Correct 195 ms 30952 KB Output is correct
15 Correct 387 ms 47696 KB Output is correct
16 Correct 308 ms 46036 KB Output is correct
17 Correct 335 ms 44812 KB Output is correct
18 Correct 330 ms 43828 KB Output is correct
19 Correct 12 ms 2516 KB Output is correct
20 Correct 158 ms 23364 KB Output is correct
21 Correct 241 ms 42612 KB Output is correct
22 Correct 426 ms 47680 KB Output is correct
23 Correct 494 ms 52864 KB Output is correct
24 Correct 313 ms 46596 KB Output is correct
25 Correct 329 ms 45896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 15324 KB Output is correct
2 Execution timed out 4073 ms 220480 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 15324 KB Output is correct
2 Execution timed out 4073 ms 220480 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 300 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1502 ms 73480 KB Output is correct
21 Correct 1269 ms 97272 KB Output is correct
22 Correct 348 ms 42920 KB Output is correct
23 Correct 364 ms 40168 KB Output is correct
24 Correct 336 ms 42688 KB Output is correct
25 Correct 1865 ms 90280 KB Output is correct
26 Correct 488 ms 46284 KB Output is correct
27 Correct 1732 ms 122792 KB Output is correct
28 Correct 596 ms 48292 KB Output is correct
29 Correct 463 ms 50340 KB Output is correct
30 Correct 1440 ms 112484 KB Output is correct
31 Correct 195 ms 30952 KB Output is correct
32 Correct 387 ms 47696 KB Output is correct
33 Correct 308 ms 46036 KB Output is correct
34 Correct 335 ms 44812 KB Output is correct
35 Correct 330 ms 43828 KB Output is correct
36 Correct 12 ms 2516 KB Output is correct
37 Correct 158 ms 23364 KB Output is correct
38 Correct 241 ms 42612 KB Output is correct
39 Correct 426 ms 47680 KB Output is correct
40 Correct 494 ms 52864 KB Output is correct
41 Correct 313 ms 46596 KB Output is correct
42 Correct 329 ms 45896 KB Output is correct
43 Correct 114 ms 15324 KB Output is correct
44 Execution timed out 4073 ms 220480 KB Time limit exceeded
45 Halted 0 ms 0 KB -