답안 #723969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723969 2023-04-14T14:30:37 Z GrandTiger1729 Sky Walking (IOI19_walk) C++17
24 / 100
4000 ms 387764 KB
#include "walk.h"
#ifndef EVAL
#include "grader.cpp"
#endif

#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18;
long long min_distance(vector<int> a, vector<int> h, vector<int> l, vector<int> r, vector<int> b, int S, int T){
	int n = a.size(), m = l.size();
	vector<int> ord(n), dt(m);
	iota(ord.begin(), ord.end(), 0);
	sort(ord.begin(), ord.end(), [&](auto x, auto y){
		return h[x] > h[y];
	});
	iota(dt.begin(), dt.end(), 0);
	sort(dt.begin(), dt.end(), [&](auto x, auto y){
		return b[x] > b[y];
	});
	set<int> st;
	map<pair<int, int>, int> mp;
	auto idx = [&](int x, int y) -> int {
		if (mp.find(make_pair(x, y)) == mp.end())
			return mp[make_pair(x, y)] = mp.size();
		return mp[make_pair(x, y)];
	};
	vector<vector<pair<int, int>>> g;
	vector<vector<int>> pos(n);
	{
		int j = 0;
		for (int &i: dt){
			while (j < n && h[ord[j]] >= b[i]){
				st.insert(ord[j]);
				j++;
			}
			// cerr << ":::" << endl;
			auto it = st.lower_bound(l[i]);
			// cerr << *it << endl;
			while (it != st.end() && *it != r[i]){
				auto it2 = it;
				it++;
				int u = idx(*it2, b[i]), v = idx(*it, b[i]);
				pos[*it2].push_back(b[i]);
				pos[*it].push_back(b[i]);
				g.resize(mp.size());
				g[u].emplace_back(v, a[*it] - a[*it2]);
				g[v].emplace_back(u, a[*it] - a[*it2]);
			}
		}
	}
	// cerr << "OK" << endl;
	idx(S, 0), idx(T, 0);
	// cerr << idx(S, 0) << ' ' << idx(T, 0) << endl;
	pos[S].push_back(0);
	pos[T].push_back(0);
	// cerr << endl;
	// for (int i = 0; i < n; i++)
	// 	cerr << pos[i].size() << ' ';
	// cerr << endl;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < (int)pos[i].size() - 1; j++){
			int u = idx(i, pos[i][j]), v = idx(i, pos[i][j + 1]);
			// cerr << u << ' ' << v << endl;
			g.resize(mp.size());
			g[u].emplace_back(v, pos[i][j] - pos[i][j + 1]);
			g[v].emplace_back(u, pos[i][j] - pos[i][j + 1]);
		}
	}
	// cerr << "OK2" << endl;
	int N = g.size();
	// for (int i = 0; i < N; i++)
	// 	for (auto &[v, w]: g[i])
	// 		cerr << i << ' ' << v << ' ' << w << endl;
	priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<>> pq;
	vector<bool> vis(N);
	vector<long long> dis(N, INF);
	pq.emplace(0, idx(S, 0));
	dis[idx(S, 0)] = 0;
	while (pq.size()){
		auto [d, u] = pq.top();
		pq.pop();
		if (vis[u]) continue;
		vis[u] = 1;
		for (auto &[v, w]: g[u]){
			if (dis[v] > dis[u] + w){
				dis[v] = dis[u] + w;
				pq.emplace(dis[v], v);
			}
		}
	}
	// cerr << endl << g[idx(S, 0)].size() << endl;
	// for (int i = 0; i < N; i++)
	// 	cerr << dis[i] << ' ';
	// cerr << endl;
	long long ans = dis[idx(T, 0)];
	return ans >= INF? -1: ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 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 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 2 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1884 ms 143836 KB Output is correct
4 Correct 1719 ms 148428 KB Output is correct
5 Correct 1225 ms 128820 KB Output is correct
6 Correct 1034 ms 112260 KB Output is correct
7 Correct 1185 ms 128608 KB Output is correct
8 Correct 2453 ms 185768 KB Output is correct
9 Correct 1405 ms 126276 KB Output is correct
10 Correct 2409 ms 213468 KB Output is correct
11 Correct 908 ms 69872 KB Output is correct
12 Correct 526 ms 41256 KB Output is correct
13 Correct 2070 ms 184972 KB Output is correct
14 Correct 381 ms 40844 KB Output is correct
15 Correct 426 ms 41100 KB Output is correct
16 Correct 383 ms 43672 KB Output is correct
17 Correct 486 ms 42396 KB Output is correct
18 Correct 286 ms 42484 KB Output is correct
19 Correct 9 ms 2292 KB Output is correct
20 Correct 132 ms 20244 KB Output is correct
21 Correct 393 ms 39216 KB Output is correct
22 Correct 466 ms 40972 KB Output is correct
23 Correct 390 ms 54880 KB Output is correct
24 Correct 401 ms 41944 KB Output is correct
25 Correct 457 ms 41792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 15752 KB Output is correct
2 Execution timed out 4083 ms 387764 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 15752 KB Output is correct
2 Execution timed out 4083 ms 387764 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 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 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 2 ms 420 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1884 ms 143836 KB Output is correct
21 Correct 1719 ms 148428 KB Output is correct
22 Correct 1225 ms 128820 KB Output is correct
23 Correct 1034 ms 112260 KB Output is correct
24 Correct 1185 ms 128608 KB Output is correct
25 Correct 2453 ms 185768 KB Output is correct
26 Correct 1405 ms 126276 KB Output is correct
27 Correct 2409 ms 213468 KB Output is correct
28 Correct 908 ms 69872 KB Output is correct
29 Correct 526 ms 41256 KB Output is correct
30 Correct 2070 ms 184972 KB Output is correct
31 Correct 381 ms 40844 KB Output is correct
32 Correct 426 ms 41100 KB Output is correct
33 Correct 383 ms 43672 KB Output is correct
34 Correct 486 ms 42396 KB Output is correct
35 Correct 286 ms 42484 KB Output is correct
36 Correct 9 ms 2292 KB Output is correct
37 Correct 132 ms 20244 KB Output is correct
38 Correct 393 ms 39216 KB Output is correct
39 Correct 466 ms 40972 KB Output is correct
40 Correct 390 ms 54880 KB Output is correct
41 Correct 401 ms 41944 KB Output is correct
42 Correct 457 ms 41792 KB Output is correct
43 Correct 124 ms 15752 KB Output is correct
44 Execution timed out 4083 ms 387764 KB Time limit exceeded
45 Halted 0 ms 0 KB -