Submission #1048857

# Submission time Handle Problem Language Result Execution time Memory
1048857 2024-08-08T09:56:16 Z dozer Sky Walking (IOI19_walk) C++14
10 / 100
4000 ms 243032 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#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) {
	int n = x.size(), m = l.size();
	vector<map<int, long long>> dist(n);
	vector<vector<pii>> adj(n);
	vector<vector<int>> points(n);
	vector<array<int, 3>> events;
	vector<int> last(m, -1);



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


	int it = 0;

	for (int i = 0; i < n; i++){
		while(it < events.size() && events[it][0] == i){
			int 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()){
			points[i].pb(-it2->st);
			int ind = it2->nd;
			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 (int i = 0; i < n; i++){
		sort(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;
		//cout<<X<<sp<<y<<sp<<d<<endl;
		int pos = lower_bound(points[X].begin(), points[X].end(), y) - points[X].begin();
		if (pos > 0){
			int to = points[X][pos - 1];
			ll tmp = d + abs(to - y);
			if (dist[X].count(to) == 0 || dist[X][to] > tmp){
				dist[X][to] = tmp;
				q.push({-tmp, X, to});
			}
		}
		if (pos < points[X].size()){
			int to = points[X][pos + 1];
			ll tmp = d + 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((int)y, 0)) - adj[X].begin();
		while(pos < adj[X].size() && adj[X][pos].st == y){
			int to = adj[X][pos].nd;
			ll tmp = d + 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:37:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   while(it < events.size() && events[it][0] == i){
      |         ~~~^~~~~~~~~~~~~~~
walk.cpp:82:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |   if (pos < points[X].size()){
      |       ~~~~^~~~~~~~~~~~~~~~~~
walk.cpp:92:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |   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 1 ms 348 KB Output is correct
7 Correct 0 ms 436 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 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 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# 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 610 ms 69924 KB Output is correct
4 Correct 359 ms 87740 KB Output is correct
5 Correct 142 ms 33732 KB Output is correct
6 Correct 93 ms 31172 KB Output is correct
7 Correct 93 ms 33596 KB Output is correct
8 Correct 831 ms 87000 KB Output is correct
9 Correct 150 ms 39368 KB Output is correct
10 Correct 520 ms 115744 KB Output is correct
11 Correct 208 ms 44544 KB Output is correct
12 Correct 88 ms 42076 KB Output is correct
13 Correct 403 ms 105452 KB Output is correct
14 Correct 89 ms 23132 KB Output is correct
15 Correct 108 ms 41960 KB Output is correct
16 Incorrect 166 ms 40632 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 10592 KB Output is correct
2 Execution timed out 4046 ms 243032 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 10592 KB Output is correct
2 Execution timed out 4046 ms 243032 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 1 ms 348 KB Output is correct
7 Correct 0 ms 436 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 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 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 1 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 610 ms 69924 KB Output is correct
21 Correct 359 ms 87740 KB Output is correct
22 Correct 142 ms 33732 KB Output is correct
23 Correct 93 ms 31172 KB Output is correct
24 Correct 93 ms 33596 KB Output is correct
25 Correct 831 ms 87000 KB Output is correct
26 Correct 150 ms 39368 KB Output is correct
27 Correct 520 ms 115744 KB Output is correct
28 Correct 208 ms 44544 KB Output is correct
29 Correct 88 ms 42076 KB Output is correct
30 Correct 403 ms 105452 KB Output is correct
31 Correct 89 ms 23132 KB Output is correct
32 Correct 108 ms 41960 KB Output is correct
33 Incorrect 166 ms 40632 KB Output isn't correct
34 Halted 0 ms 0 KB -