Submission #825824

# Submission time Handle Problem Language Result Execution time Memory
825824 2023-08-15T08:34:08 Z tomruk Sky Walking (IOI19_walk) C++17
57 / 100
4000 ms 480928 KB
#include "walk.h"
#include <bits/stdc++.h>
#define N 100005
using namespace std;
map<int,vector<int>> adj[N];
map<int,long long> d[N];
vector<int> vv[N];
vector<int> add[N];
vector<int> del[N];
long long min_distance(vector<int> p, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g){
	int n = p.size();
	int m = l.size();
	if(s == 0 && g == n-1){
		vector<pair<int,int>> v;
		for(int i = 0;i<n;i++){
			v.push_back({h[i],i});
			adj[i][0].push_back(i);
		}
		for(int i = 0;i<m;i++){
			vv[r[i]].push_back(i);
			v.push_back({y[i],~i});
			add[r[i]].push_back(i);
			del[l[i]].push_back(i);
		}
		set<pair<int,int>> act;
		for(int i = n-1;i>=0;i--){
			for(auto u:add[i]){
				act.insert({y[u],u});
			}
			// cout << "asdasd" << endl;
			// cout << i << endl;
			// for(auto u:act){
			// 	cout << u.first << " " << u.second << endl;
			// }
			for(auto u:vv[i]){
				// cout << u << endl;
				auto it = act.lower_bound({y[u],u});
				if(next(it) != act.end()){
					adj[i][next(it)->first].push_back(r[next(it)->second]);
					adj[r[next(it)->second]][next(it)->first].push_back(i);
				}
				if(it != act.begin()){
					adj[i][prev(it)->first].push_back(r[prev(it)->second]);
					adj[r[prev(it)->second]][prev(it)->first].push_back(i);
				}
			}
			for(auto u:del[i]){
				act.erase({y[u],u});
			}
		}
		sort(v.rbegin(),v.rend());
		set<int> active;
		for(auto u:v){
			if(u.second < 0){
				u.second = ~u.second;
				auto it = active.lower_bound(max(s,l[u.second]));
				auto it2 = active.lower_bound(min(g,r[u.second]));
				adj[*it][y[u.second]].push_back(*it2);
				adj[*it2][y[u.second]].push_back(*it);
				// while(1){
				// 	auto it2 = it;
				// 	it2++;
				// 	if(it2 == active.end() || *it2 > r[u.second])
				// 		break;
				// 	adj[*it][y[u.second]].push_back(*it2);
				// 	adj[*it2][y[u.second]].push_back(*it);
				// 	it = it2;
				// }
			}
			else{
				active.insert(u.second);
			}
		}
		priority_queue<pair<long long,pair<int,int>>> q;
		d[s][0] = 0;
		q.push({-d[s][0],{s,0}});
		while(q.size()){
			auto tp = q.top();
			q.pop();
			tp.first *= -1;
			int x = tp.second.first;
			int y = tp.second.second;
			if(tp.first != d[x][y])
				continue;
			// cout << x << ' ' << y << endl;
			// cout << tp.first << endl;
			for(auto u:adj[x][y]){
				long long nw = abs(p[x] - p[u]) + tp.first;
				if(d[u].count(y) == 0 || d[u][y] > nw){
					d[u][y] = nw;
					q.push({-d[u][y],{u,y}});
				}
			}
			auto it = adj[x].find(y);
			if(next(it) != adj[x].end()){
				long long nw = abs(y - next(it)->first) + tp.first;
				if(d[x].count(next(it)->first) == 0 || d[x][next(it)->first] > nw){
					d[x][next(it)->first] = nw;
					q.push({-d[x][next(it)->first],{x,next(it)->first}});
				}
			}
			if(it != adj[x].begin()){
				long long nw = abs(y - prev(it)->first) + tp.first;
				if(d[x].count(prev(it)->first) == 0 || d[x][prev(it)->first] > nw){
					d[x][prev(it)->first] = nw;
					q.push({-d[x][prev(it)->first],{x,prev(it)->first}});
				}
			}
		}
		return (d[g].count(0)?d[g][0]:-1);
	}
		vector<pair<int,int>> v;
	for(int i = 0;i<n;i++){
		v.push_back({h[i],i});
		adj[i][0].push_back(i);
	}
	for(int i = 0;i<m;i++){
		v.push_back({y[i],~i});
	}
	sort(v.rbegin(),v.rend());
	set<int> active;
	for(auto u:v){
		if(u.second < 0){
			u.second = ~u.second;
			auto it = active.lower_bound(l[u.second]);
			while(1){
				auto it2 = it;
				it2++;
				if(it2 == active.end() || *it2 > r[u.second])
					break;
				adj[*it][y[u.second]].push_back(*it2);
				adj[*it2][y[u.second]].push_back(*it);
				it = it2;
			}
		}
		else{
			active.insert(u.second);
		}
	}
	priority_queue<pair<long long,pair<int,int>>> q;
	d[s][0] = 0;
	q.push({-d[s][0],{s,0}});
	while(q.size()){
		auto tp = q.top();
		q.pop();
		tp.first *= -1;
		int x = tp.second.first;
		int y = tp.second.second;
		if(tp.first != d[x][y])
			continue;
		// cout << x << ' ' << y << endl;
		// cout << tp.first << endl;
		for(auto u:adj[x][y]){
			long long nw = abs(p[x] - p[u]) + tp.first;
			if(d[u].count(y) == 0 || d[u][y] > nw){
				d[u][y] = nw;
				q.push({-d[u][y],{u,y}});
			}
		}
		auto it = adj[x].find(y);
		if(next(it) != adj[x].end()){
			long long nw = abs(y - next(it)->first) + tp.first;
			if(d[x].count(next(it)->first) == 0 || d[x][next(it)->first] > nw){
				d[x][next(it)->first] = nw;
				q.push({-d[x][next(it)->first],{x,next(it)->first}});
			}
		}
		if(it != adj[x].begin()){
			long long nw = abs(y - prev(it)->first) + tp.first;
			if(d[x].count(prev(it)->first) == 0 || d[x][prev(it)->first] > nw){
				d[x][prev(it)->first] = nw;
				q.push({-d[x][prev(it)->first],{x,prev(it)->first}});
			}
		}
	}
	return (d[g].count(0)?d[g][0]:-1);
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16724 KB Output is correct
2 Correct 8 ms 16724 KB Output is correct
3 Correct 9 ms 16724 KB Output is correct
4 Correct 8 ms 16724 KB Output is correct
5 Correct 8 ms 16852 KB Output is correct
6 Correct 8 ms 16724 KB Output is correct
7 Correct 8 ms 16724 KB Output is correct
8 Correct 8 ms 16724 KB Output is correct
9 Correct 8 ms 16680 KB Output is correct
10 Correct 9 ms 16852 KB Output is correct
11 Correct 8 ms 16724 KB Output is correct
12 Correct 9 ms 16724 KB Output is correct
13 Correct 8 ms 16724 KB Output is correct
14 Correct 8 ms 16736 KB Output is correct
15 Correct 8 ms 16676 KB Output is correct
16 Correct 8 ms 16768 KB Output is correct
17 Correct 8 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16724 KB Output is correct
2 Correct 9 ms 16740 KB Output is correct
3 Correct 1228 ms 142984 KB Output is correct
4 Correct 738 ms 164724 KB Output is correct
5 Correct 346 ms 103072 KB Output is correct
6 Correct 313 ms 94280 KB Output is correct
7 Correct 358 ms 103096 KB Output is correct
8 Correct 1692 ms 177224 KB Output is correct
9 Correct 483 ms 107580 KB Output is correct
10 Correct 1107 ms 216348 KB Output is correct
11 Correct 416 ms 89752 KB Output is correct
12 Correct 319 ms 87992 KB Output is correct
13 Correct 528 ms 114656 KB Output is correct
14 Correct 162 ms 58344 KB Output is correct
15 Correct 235 ms 78564 KB Output is correct
16 Correct 234 ms 78268 KB Output is correct
17 Correct 238 ms 76308 KB Output is correct
18 Correct 564 ms 76756 KB Output is correct
19 Correct 15 ms 19600 KB Output is correct
20 Correct 97 ms 46420 KB Output is correct
21 Correct 307 ms 79500 KB Output is correct
22 Correct 382 ms 97532 KB Output is correct
23 Correct 461 ms 95340 KB Output is correct
24 Correct 321 ms 92920 KB Output is correct
25 Correct 308 ms 86316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 32836 KB Output is correct
2 Correct 828 ms 88876 KB Output is correct
3 Correct 760 ms 93524 KB Output is correct
4 Correct 1010 ms 118960 KB Output is correct
5 Correct 1284 ms 117256 KB Output is correct
6 Correct 1102 ms 111364 KB Output is correct
7 Correct 422 ms 80892 KB Output is correct
8 Correct 344 ms 87880 KB Output is correct
9 Correct 882 ms 104960 KB Output is correct
10 Correct 432 ms 87140 KB Output is correct
11 Correct 39 ms 25648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 32836 KB Output is correct
2 Correct 828 ms 88876 KB Output is correct
3 Correct 760 ms 93524 KB Output is correct
4 Correct 1010 ms 118960 KB Output is correct
5 Correct 1284 ms 117256 KB Output is correct
6 Correct 1102 ms 111364 KB Output is correct
7 Correct 422 ms 80892 KB Output is correct
8 Correct 344 ms 87880 KB Output is correct
9 Correct 882 ms 104960 KB Output is correct
10 Correct 432 ms 87140 KB Output is correct
11 Correct 39 ms 25648 KB Output is correct
12 Correct 761 ms 93252 KB Output is correct
13 Correct 475 ms 87868 KB Output is correct
14 Correct 1191 ms 117172 KB Output is correct
15 Correct 730 ms 107940 KB Output is correct
16 Correct 772 ms 107480 KB Output is correct
17 Correct 848 ms 119344 KB Output is correct
18 Correct 748 ms 107952 KB Output is correct
19 Correct 789 ms 107704 KB Output is correct
20 Correct 436 ms 78488 KB Output is correct
21 Correct 71 ms 35292 KB Output is correct
22 Correct 558 ms 98636 KB Output is correct
23 Correct 525 ms 97404 KB Output is correct
24 Correct 460 ms 90428 KB Output is correct
25 Correct 517 ms 92936 KB Output is correct
26 Correct 416 ms 92604 KB Output is correct
27 Correct 1206 ms 118476 KB Output is correct
28 Correct 431 ms 87240 KB Output is correct
29 Correct 1020 ms 111332 KB Output is correct
30 Correct 482 ms 80884 KB Output is correct
31 Correct 941 ms 104684 KB Output is correct
32 Correct 379 ms 85248 KB Output is correct
33 Correct 384 ms 91944 KB Output is correct
34 Correct 457 ms 90872 KB Output is correct
35 Correct 428 ms 96408 KB Output is correct
36 Correct 345 ms 89112 KB Output is correct
37 Correct 313 ms 79476 KB Output is correct
38 Correct 418 ms 97468 KB Output is correct
39 Correct 486 ms 95296 KB Output is correct
40 Correct 340 ms 92876 KB Output is correct
41 Correct 333 ms 86248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16724 KB Output is correct
2 Correct 8 ms 16724 KB Output is correct
3 Correct 9 ms 16724 KB Output is correct
4 Correct 8 ms 16724 KB Output is correct
5 Correct 8 ms 16852 KB Output is correct
6 Correct 8 ms 16724 KB Output is correct
7 Correct 8 ms 16724 KB Output is correct
8 Correct 8 ms 16724 KB Output is correct
9 Correct 8 ms 16680 KB Output is correct
10 Correct 9 ms 16852 KB Output is correct
11 Correct 8 ms 16724 KB Output is correct
12 Correct 9 ms 16724 KB Output is correct
13 Correct 8 ms 16724 KB Output is correct
14 Correct 8 ms 16736 KB Output is correct
15 Correct 8 ms 16676 KB Output is correct
16 Correct 8 ms 16768 KB Output is correct
17 Correct 8 ms 16724 KB Output is correct
18 Correct 8 ms 16724 KB Output is correct
19 Correct 9 ms 16740 KB Output is correct
20 Correct 1228 ms 142984 KB Output is correct
21 Correct 738 ms 164724 KB Output is correct
22 Correct 346 ms 103072 KB Output is correct
23 Correct 313 ms 94280 KB Output is correct
24 Correct 358 ms 103096 KB Output is correct
25 Correct 1692 ms 177224 KB Output is correct
26 Correct 483 ms 107580 KB Output is correct
27 Correct 1107 ms 216348 KB Output is correct
28 Correct 416 ms 89752 KB Output is correct
29 Correct 319 ms 87992 KB Output is correct
30 Correct 528 ms 114656 KB Output is correct
31 Correct 162 ms 58344 KB Output is correct
32 Correct 235 ms 78564 KB Output is correct
33 Correct 234 ms 78268 KB Output is correct
34 Correct 238 ms 76308 KB Output is correct
35 Correct 564 ms 76756 KB Output is correct
36 Correct 15 ms 19600 KB Output is correct
37 Correct 97 ms 46420 KB Output is correct
38 Correct 307 ms 79500 KB Output is correct
39 Correct 382 ms 97532 KB Output is correct
40 Correct 461 ms 95340 KB Output is correct
41 Correct 321 ms 92920 KB Output is correct
42 Correct 308 ms 86316 KB Output is correct
43 Correct 111 ms 32836 KB Output is correct
44 Correct 828 ms 88876 KB Output is correct
45 Correct 760 ms 93524 KB Output is correct
46 Correct 1010 ms 118960 KB Output is correct
47 Correct 1284 ms 117256 KB Output is correct
48 Correct 1102 ms 111364 KB Output is correct
49 Correct 422 ms 80892 KB Output is correct
50 Correct 344 ms 87880 KB Output is correct
51 Correct 882 ms 104960 KB Output is correct
52 Correct 432 ms 87140 KB Output is correct
53 Correct 39 ms 25648 KB Output is correct
54 Correct 761 ms 93252 KB Output is correct
55 Correct 475 ms 87868 KB Output is correct
56 Correct 1191 ms 117172 KB Output is correct
57 Correct 730 ms 107940 KB Output is correct
58 Correct 772 ms 107480 KB Output is correct
59 Correct 848 ms 119344 KB Output is correct
60 Correct 748 ms 107952 KB Output is correct
61 Correct 789 ms 107704 KB Output is correct
62 Correct 436 ms 78488 KB Output is correct
63 Correct 71 ms 35292 KB Output is correct
64 Correct 558 ms 98636 KB Output is correct
65 Correct 525 ms 97404 KB Output is correct
66 Correct 460 ms 90428 KB Output is correct
67 Correct 517 ms 92936 KB Output is correct
68 Correct 416 ms 92604 KB Output is correct
69 Correct 1206 ms 118476 KB Output is correct
70 Correct 431 ms 87240 KB Output is correct
71 Correct 1020 ms 111332 KB Output is correct
72 Correct 482 ms 80884 KB Output is correct
73 Correct 941 ms 104684 KB Output is correct
74 Correct 379 ms 85248 KB Output is correct
75 Correct 384 ms 91944 KB Output is correct
76 Correct 457 ms 90872 KB Output is correct
77 Correct 428 ms 96408 KB Output is correct
78 Correct 345 ms 89112 KB Output is correct
79 Correct 313 ms 79476 KB Output is correct
80 Correct 418 ms 97468 KB Output is correct
81 Correct 486 ms 95296 KB Output is correct
82 Correct 340 ms 92876 KB Output is correct
83 Correct 333 ms 86248 KB Output is correct
84 Correct 64 ms 30148 KB Output is correct
85 Execution timed out 4089 ms 480928 KB Time limit exceeded
86 Halted 0 ms 0 KB -