답안 #1026810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026810 2024-07-18T11:43:32 Z fv3 Sky Walking (IOI19_walk) C++14
10 / 100
4000 ms 1048576 KB
/*
Sky Walking
*/
#include <bits/stdc++.h>
#include "walk.h"

using namespace std;
typedef long long ll;
const ll INF = 1ll << 60ll;

struct node
{
	ll x, y; 
	ll index;
	vector<pair<int, ll>> adj;
};

struct walk
{
	int l, r, y;
	bool operator<(const walk other) const
	{
		return y < other.y;
	}
};

ll min_distance(vector<int> X, vector<int> H, vector<int> L, vector<int> R, vector<int> Y, int S, int G) 
{
	const int N = X.size();
	const int M = L.size();

	vector<walk> walks(M);
	for (int i = 0; i < M; i++)
		walks[i] = {L[i], R[i], Y[i]};
	sort(walks.begin(), walks.end());

	// Construct adjacency list
	vector<node> nodes;
	vector<int> top(N);
	for (int i = 0; i < N; i++)
	{
		nodes.push_back({X[i], 0, i, {}});
		top[i] = i; 
	}

	for (auto w : walks)
	{
		int last = -1;
		for (int i = w.l; i <= w.r; i++)
		{
			if (H[i] < w.y) continue;

			int index = nodes.size();
			node newNode = {X[i], w.y, index, {}};

			ll vdist = w.y - nodes[top[i]].y;

			nodes[top[i]].adj.push_back({index, vdist});
			newNode.adj.push_back({top[i], vdist});
			top[i] = index;

			if (last != -1)
			{
				ll hdist = X[i] - nodes[last].x;

				newNode.adj.push_back({last, hdist});
				nodes[last].adj.push_back({index, hdist});
			}
			last = index;

			nodes.push_back(newNode);
		}
	}

	priority_queue<pair<ll, int>> q;
	q.push({0ll, S});

	ll sz = nodes.size();

	vector<int> visited(sz);
	vector<ll> dist(sz, INF);
	dist[S] = 0;

	while (!q.empty())
	{
		int s = q.top().second;
		q.pop();

		if (visited[s]) continue;
		visited[s] = 1;

		for (auto n : nodes[s].adj)
		{
			if (visited[n.first]) continue;
			if (dist[s] + n.second < dist[n.first])
			{
				dist[n.first] = dist[s] + n.second;
				q.push({-dist[n.first], n.first});
			}
		}
	}

	if (dist[G] == INF)
		return -1;
	return dist[G];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 436 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 363 ms 104456 KB Output is correct
4 Correct 344 ms 114852 KB Output is correct
5 Correct 191 ms 99840 KB Output is correct
6 Correct 493 ms 94892 KB Output is correct
7 Correct 183 ms 99448 KB Output is correct
8 Correct 428 ms 132244 KB Output is correct
9 Correct 206 ms 98724 KB Output is correct
10 Correct 433 ms 185764 KB Output is correct
11 Correct 185 ms 60076 KB Output is correct
12 Correct 115 ms 48056 KB Output is correct
13 Correct 368 ms 138152 KB Output is correct
14 Correct 1675 ms 47288 KB Output is correct
15 Correct 861 ms 47792 KB Output is correct
16 Correct 139 ms 47028 KB Output is correct
17 Correct 162 ms 47292 KB Output is correct
18 Execution timed out 4064 ms 29280 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 18576 KB Output is correct
2 Correct 1930 ms 729416 KB Output is correct
3 Runtime error 1098 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 18576 KB Output is correct
2 Correct 1930 ms 729416 KB Output is correct
3 Runtime error 1098 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 436 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 363 ms 104456 KB Output is correct
21 Correct 344 ms 114852 KB Output is correct
22 Correct 191 ms 99840 KB Output is correct
23 Correct 493 ms 94892 KB Output is correct
24 Correct 183 ms 99448 KB Output is correct
25 Correct 428 ms 132244 KB Output is correct
26 Correct 206 ms 98724 KB Output is correct
27 Correct 433 ms 185764 KB Output is correct
28 Correct 185 ms 60076 KB Output is correct
29 Correct 115 ms 48056 KB Output is correct
30 Correct 368 ms 138152 KB Output is correct
31 Correct 1675 ms 47288 KB Output is correct
32 Correct 861 ms 47792 KB Output is correct
33 Correct 139 ms 47028 KB Output is correct
34 Correct 162 ms 47292 KB Output is correct
35 Execution timed out 4064 ms 29280 KB Time limit exceeded
36 Halted 0 ms 0 KB -