Submission #1049013

# Submission time Handle Problem Language Result Execution time Memory
1049013 2024-08-08T12:00:17 Z dozer Sky Walking (IOI19_walk) C++14
24 / 100
4000 ms 363248 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<ll, ll>
#define st first
#define nd second
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define LL node * 2
#define RR node * 2 + 1
#define ll long long


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) {
	ll n = x.size(), m = l.size();
	vector<map<ll, long long>> dist(n);
	vector<vector<pii>> adj(n);
	vector<vector<ll>> points(n);
	vector<array<ll, 3>> events;
	vector<ll> last(m, -1);

	set<pii> open;
	for (ll i = 0; i < m; i++)
		events.pb({l[i], i, -1}), events.pb({r[i] + 1, i, 1});
	sort(events.begin(), events.end());

	ll it = 0;

	for (ll i = 0; i < n; i++){
		while(it < events.size() && events[it][0] == i){
			ll t = events[it][2], ind = events[it][1];
			if (t == -1) open.insert({-y[ind], ind});
			else open.erase({-y[ind], ind});
			it++;
		}

		auto it2 = open.lower_bound({-h[i], 0});
		while(it2 != open.end()){
			ll ind = it2->nd;
			points[i].pb(y[ind]);
			if (last[ind] != -1){
				adj[i].pb({y[ind], last[ind]});
				adj[last[ind]].pb({y[ind], i});
			}
			last[ind] = i;
			it2++;
		}
		points[i].pb(0);
	}

	for (ll i = 0; i < n; i++){
		sort(points[i].begin(), points[i].end());
		unique(points[i].begin(), points[i].end());
		sort(adj[i].begin(), adj[i].end());
	}

	priority_queue<array<long long, 3>> q;
	q.push({0, s, 0});
	dist[s][0] = 0;
	while(!q.empty()){
		array<ll, 3> tmp = q.top();
		q.pop();
		long long X = tmp[1], y = tmp[2], d = -tmp[0];
		if (dist[X][y] < d) continue;
		ll pos = lower_bound(points[X].begin(), points[X].end(), y) - points[X].begin();
		if (pos > 0){
			ll to = points[X][pos - 1];
			ll tmp = d + (ll)abs(to - y);
			if (dist[X].count(to) == 0 || dist[X][to] > tmp){
				dist[X][to] = tmp;
				q.push({-tmp, X, to});
			}
		}
		if (pos + 1 < points[X].size()){
			ll to = points[X][pos + 1];
			ll tmp = d + (ll)abs(to - y);
			if (dist[X].count(to) == 0 || dist[X][to] > tmp){
				dist[X][to] = tmp;
				q.push({-tmp, X, to});
			}
		}

		pos = lower_bound(adj[X].begin(), adj[X].end(), make_pair(y, (ll)0)) - adj[X].begin();
		while(pos < adj[X].size() && adj[X][pos].st == y){
			ll to = adj[X][pos].nd;
			ll tmp = d + (ll)abs(x[X] - x[to]);
			if (dist[to].count(y) == 0 || dist[to][y] > tmp){
				dist[to][y] = tmp;
				q.push({-tmp, to, y});
			}
			pos++;
		}
	}

	if (dist[g].count(0)) return dist[g][0];
	return -1;
}
/*

int main() {
	fileio();
	int n, m;
	assert(2 == scanf("%d%d", &n, &m));
	vector<int> x(n), h(n);
	for (int i = 0; i < n; i++)
		assert(2 == scanf("%d%d", &x[i], &h[i]));
	vector<int> l(m), r(m), y(m);
	for (int i = 0; i < m; i++)
		assert(3 == scanf("%d%d%d", &l[i], &r[i], &y[i]));
	int s, g;
	assert(2 == scanf("%d%d", &s, &g));
	fclose(stdin);

	long long result = min_distance(x, h, l, r, y, s, g);

	printf("%lld\n", result);
	fclose(stdout);
	return 0;
}
*/

Compilation message

walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:33:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   while(it < events.size() && events[it][0] == i){
      |         ~~~^~~~~~~~~~~~~~~
walk.cpp:77:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   if (pos + 1 < points[X].size()){
      |       ~~~~~~~~^~~~~~~~~~~~~~~~~~
walk.cpp:87:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   while(pos < adj[X].size() && adj[X][pos].st == y){
      |         ~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 553 ms 91480 KB Output is correct
4 Correct 318 ms 105180 KB Output is correct
5 Correct 103 ms 50896 KB Output is correct
6 Correct 99 ms 46276 KB Output is correct
7 Correct 105 ms 50360 KB Output is correct
8 Correct 785 ms 112152 KB Output is correct
9 Correct 148 ms 56368 KB Output is correct
10 Correct 471 ms 143540 KB Output is correct
11 Correct 196 ms 53184 KB Output is correct
12 Correct 91 ms 47292 KB Output is correct
13 Correct 375 ms 132296 KB Output is correct
14 Correct 76 ms 28092 KB Output is correct
15 Correct 104 ms 48568 KB Output is correct
16 Correct 107 ms 47556 KB Output is correct
17 Correct 104 ms 49592 KB Output is correct
18 Correct 233 ms 51720 KB Output is correct
19 Correct 5 ms 2908 KB Output is correct
20 Correct 46 ms 25824 KB Output is correct
21 Correct 83 ms 45308 KB Output is correct
22 Correct 101 ms 50364 KB Output is correct
23 Correct 198 ms 64176 KB Output is correct
24 Correct 101 ms 49852 KB Output is correct
25 Correct 91 ms 47808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 13768 KB Output is correct
2 Execution timed out 4096 ms 363248 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 13768 KB Output is correct
2 Execution timed out 4096 ms 363248 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 428 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 553 ms 91480 KB Output is correct
21 Correct 318 ms 105180 KB Output is correct
22 Correct 103 ms 50896 KB Output is correct
23 Correct 99 ms 46276 KB Output is correct
24 Correct 105 ms 50360 KB Output is correct
25 Correct 785 ms 112152 KB Output is correct
26 Correct 148 ms 56368 KB Output is correct
27 Correct 471 ms 143540 KB Output is correct
28 Correct 196 ms 53184 KB Output is correct
29 Correct 91 ms 47292 KB Output is correct
30 Correct 375 ms 132296 KB Output is correct
31 Correct 76 ms 28092 KB Output is correct
32 Correct 104 ms 48568 KB Output is correct
33 Correct 107 ms 47556 KB Output is correct
34 Correct 104 ms 49592 KB Output is correct
35 Correct 233 ms 51720 KB Output is correct
36 Correct 5 ms 2908 KB Output is correct
37 Correct 46 ms 25824 KB Output is correct
38 Correct 83 ms 45308 KB Output is correct
39 Correct 101 ms 50364 KB Output is correct
40 Correct 198 ms 64176 KB Output is correct
41 Correct 101 ms 49852 KB Output is correct
42 Correct 91 ms 47808 KB Output is correct
43 Correct 33 ms 13768 KB Output is correct
44 Execution timed out 4096 ms 363248 KB Time limit exceeded
45 Halted 0 ms 0 KB -