Submission #834981

# Submission time Handle Problem Language Result Execution time Memory
834981 2023-08-23T04:29:04 Z tranxuanbach Sky Walking (IOI19_walk) C++17
24 / 100
4000 ms 683308 KB
#include "walk.h"

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

#define isz(a) ((signed)a.size())

using ll = long long;
template <class T>
using min_heap = priority_queue <T, vector <T>, greater <T>>;

const int N = 1e5 + 5;

struct building{
	int x, h;
	int idx;

	friend bool operator< (const building& lhs, const building& rhs){
		return lhs.h < rhs.h;
	}
};

struct skywalk{
	int l, r, y;
	int idx;

	friend bool operator< (const skywalk& lhs, const skywalk& rhs){
		return lhs.y < rhs.y;
	}
};

int n, m;
building a[N];
skywalk b[N];
int s, t;

namespace subtask12{
	bool check(){
		return true;
	}

	vector <vector <int>> pos_y;
	vector <map <int, vector <pair <int, int>>>> adj;
	vector <map <int, ll>> dist;
	min_heap <tuple <ll, int, int>> pq;

	void transition(ll d, int x, int y){
		auto itr = dist[x].find(y);
		if (itr == dist[x].end()){
			dist[x][y] = d;
			pq.emplace(d, x, y);
		}
		else if (itr->second > d){
			itr->second = d;
			pq.emplace(d, x, y);
		}
	}

	ll solve(){
		pos_y.resize(n);
		pos_y[s].emplace_back(0);
		pos_y[t].emplace_back(0);
		adj.resize(n);
		dist.resize(n);

		{
			set <int> alive;
			for (int i = 0; i < n; i++){
				alive.emplace(i);
			}
			int ib = 0;
			vector <building> sa(a, a + n);
			sort(sa.begin(), sa.end());
			for (auto &[x, h, ia]: sa){
				while (ib < m and b[ib].y <= h){
					auto itr = alive.lower_bound(b[ib].l);
					int pre = -1;
					while (itr != alive.end() and *itr <= b[ib].r){
						if (not pos_y[*itr].empty()){
							auto u = pair{*itr, pos_y[*itr].back()}, v = pair{*itr, b[ib].y};
							adj[u.first][u.second].emplace_back(v);
							adj[v.first][v.second].emplace_back(u);
						}
						pos_y[*itr].emplace_back(b[ib].y);
						if (pre != -1){
							auto u = pair{pre, b[ib].y}, v = pair{*itr, b[ib].y};
							adj[u.first][u.second].emplace_back(v);
							adj[v.first][v.second].emplace_back(u);
						}
						pre = *itr;
						itr++;
					}
					ib++;
				}
				alive.erase(ia);
			}
		}
		transition(0ll, s, 0);
		while (not pq.empty()){
			auto [d, x, y] = pq.top(); pq.pop();
			if (d > dist[x][y]){
				continue;
			}
			if (x == t and y == 0){
				return d;
			}
			for (auto [tx, ty]: adj[x][y]){
				ll td = d + (abs(a[x].x - a[tx].x) + abs(y - ty));
				transition(td, tx, ty);
			}
		}
		return -1;
	}
}

ll min_distance(vector <int> _x, vector <int> _h, vector <int> _l, vector <int> _r, vector <int> _y, int _s, int _t){
	n = isz(_x); m = isz(_l);
	for (int i = 0; i < n; i++){
		int x = _x[i], h = _h[i];
		a[i] = building{x, h, i};
	}
	for (int i = 0; i < m; i++){
		int l = _l[i], r = _r[i], y = _y[i];
		b[i] = skywalk{l, r, y, i};
	}
	sort(b, b + m);
	s = _s; t = _t;

	if (subtask12::check()){
		return subtask12::solve();
	}
}

Compilation message

walk.cpp: In function 'll min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:132:1: warning: control reaches end of non-void function [-Wreturn-type]
  132 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 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 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 563 ms 100044 KB Output is correct
4 Correct 704 ms 157724 KB Output is correct
5 Correct 384 ms 102156 KB Output is correct
6 Correct 342 ms 91068 KB Output is correct
7 Correct 378 ms 102148 KB Output is correct
8 Correct 802 ms 134080 KB Output is correct
9 Correct 479 ms 105884 KB Output is correct
10 Correct 1052 ms 210284 KB Output is correct
11 Correct 341 ms 64296 KB Output is correct
12 Correct 253 ms 62120 KB Output is correct
13 Correct 870 ms 193460 KB Output is correct
14 Correct 155 ms 47564 KB Output is correct
15 Correct 203 ms 59596 KB Output is correct
16 Correct 239 ms 60676 KB Output is correct
17 Correct 216 ms 58684 KB Output is correct
18 Correct 329 ms 61180 KB Output is correct
19 Correct 6 ms 3108 KB Output is correct
20 Correct 71 ms 28976 KB Output is correct
21 Correct 209 ms 56116 KB Output is correct
22 Correct 168 ms 52684 KB Output is correct
23 Correct 256 ms 69920 KB Output is correct
24 Correct 200 ms 58340 KB Output is correct
25 Correct 225 ms 58656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 18240 KB Output is correct
2 Execution timed out 4089 ms 683308 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 18240 KB Output is correct
2 Execution timed out 4089 ms 683308 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 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 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 563 ms 100044 KB Output is correct
21 Correct 704 ms 157724 KB Output is correct
22 Correct 384 ms 102156 KB Output is correct
23 Correct 342 ms 91068 KB Output is correct
24 Correct 378 ms 102148 KB Output is correct
25 Correct 802 ms 134080 KB Output is correct
26 Correct 479 ms 105884 KB Output is correct
27 Correct 1052 ms 210284 KB Output is correct
28 Correct 341 ms 64296 KB Output is correct
29 Correct 253 ms 62120 KB Output is correct
30 Correct 870 ms 193460 KB Output is correct
31 Correct 155 ms 47564 KB Output is correct
32 Correct 203 ms 59596 KB Output is correct
33 Correct 239 ms 60676 KB Output is correct
34 Correct 216 ms 58684 KB Output is correct
35 Correct 329 ms 61180 KB Output is correct
36 Correct 6 ms 3108 KB Output is correct
37 Correct 71 ms 28976 KB Output is correct
38 Correct 209 ms 56116 KB Output is correct
39 Correct 168 ms 52684 KB Output is correct
40 Correct 256 ms 69920 KB Output is correct
41 Correct 200 ms 58340 KB Output is correct
42 Correct 225 ms 58656 KB Output is correct
43 Correct 57 ms 18240 KB Output is correct
44 Execution timed out 4089 ms 683308 KB Time limit exceeded
45 Halted 0 ms 0 KB -