답안 #825821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825821 2023-08-15T08:32:18 Z tomruk Sky Walking (IOI19_walk) C++17
33 / 100
1245 ms 119396 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();
	if(s == 0 && g == n-1){
		int m = l.size();
		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);
	}
	int m = l.size();
		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]));
				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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 16724 KB Output is correct
2 Correct 8 ms 16720 KB Output is correct
3 Correct 9 ms 16724 KB Output is correct
4 Correct 10 ms 16724 KB Output is correct
5 Correct 8 ms 16724 KB Output is correct
6 Incorrect 8 ms 16724 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16724 KB Output is correct
2 Correct 8 ms 16724 KB Output is correct
3 Incorrect 714 ms 103704 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 32800 KB Output is correct
2 Correct 880 ms 88928 KB Output is correct
3 Correct 735 ms 93596 KB Output is correct
4 Correct 912 ms 119012 KB Output is correct
5 Correct 1155 ms 117260 KB Output is correct
6 Correct 1014 ms 111296 KB Output is correct
7 Correct 451 ms 80976 KB Output is correct
8 Correct 325 ms 87880 KB Output is correct
9 Correct 896 ms 105024 KB Output is correct
10 Correct 438 ms 87156 KB Output is correct
11 Correct 32 ms 25704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 32800 KB Output is correct
2 Correct 880 ms 88928 KB Output is correct
3 Correct 735 ms 93596 KB Output is correct
4 Correct 912 ms 119012 KB Output is correct
5 Correct 1155 ms 117260 KB Output is correct
6 Correct 1014 ms 111296 KB Output is correct
7 Correct 451 ms 80976 KB Output is correct
8 Correct 325 ms 87880 KB Output is correct
9 Correct 896 ms 105024 KB Output is correct
10 Correct 438 ms 87156 KB Output is correct
11 Correct 32 ms 25704 KB Output is correct
12 Correct 817 ms 93368 KB Output is correct
13 Correct 510 ms 87868 KB Output is correct
14 Correct 1245 ms 117124 KB Output is correct
15 Correct 740 ms 107904 KB Output is correct
16 Correct 797 ms 107452 KB Output is correct
17 Correct 850 ms 119396 KB Output is correct
18 Correct 812 ms 107908 KB Output is correct
19 Correct 781 ms 107612 KB Output is correct
20 Correct 474 ms 78488 KB Output is correct
21 Correct 71 ms 35392 KB Output is correct
22 Correct 562 ms 98624 KB Output is correct
23 Correct 519 ms 97272 KB Output is correct
24 Correct 495 ms 90464 KB Output is correct
25 Correct 512 ms 93024 KB Output is correct
26 Correct 424 ms 92476 KB Output is correct
27 Correct 1151 ms 118404 KB Output is correct
28 Correct 457 ms 87308 KB Output is correct
29 Correct 1085 ms 111392 KB Output is correct
30 Correct 469 ms 80876 KB Output is correct
31 Correct 906 ms 104708 KB Output is correct
32 Correct 378 ms 85312 KB Output is correct
33 Correct 383 ms 91916 KB Output is correct
34 Correct 421 ms 90812 KB Output is correct
35 Correct 413 ms 96352 KB Output is correct
36 Correct 346 ms 89128 KB Output is correct
37 Correct 310 ms 79520 KB Output is correct
38 Correct 377 ms 97556 KB Output is correct
39 Correct 460 ms 95320 KB Output is correct
40 Correct 323 ms 92988 KB Output is correct
41 Correct 311 ms 86220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 16724 KB Output is correct
2 Correct 8 ms 16720 KB Output is correct
3 Correct 9 ms 16724 KB Output is correct
4 Correct 10 ms 16724 KB Output is correct
5 Correct 8 ms 16724 KB Output is correct
6 Incorrect 8 ms 16724 KB Output isn't correct
7 Halted 0 ms 0 KB -