Submission #1060671

# Submission time Handle Problem Language Result Execution time Memory
1060671 2024-08-15T20:35:56 Z aaaaaarroz Sky Walking (IOI19_walk) C++17
57 / 100
2477 ms 1048576 KB
    #include "walk.h"
    #include <bits/stdc++.h>
    using namespace std;
     
    const long long INF = 1e15;
     
    long long min_distance2(vector<int> x,vector<int> h,vector<int> l,
    					   vector<int> r,vector<int> y,int s,int g){
    	int n = x.size();
    	int m = l.size();
    	vector<vector<pair<int,int>>> points(n);
    	vector<vector<pair<int,int>>> adj;
    	int S = 0;
    	vector<tuple<int,int,int>> skywalks;
    	for(int i=0;i<m;i++)skywalks.emplace_back(y[i],l[i],r[i]);
    	sort(skywalks.rbegin(), skywalks.rend());
    	auto add_point = [&](int x,int h) {
    		adj.emplace_back();
    		if(!points[x].empty())adj[S].emplace_back(points[x].back().first,points[x].back().second-h);
    		if(!points[x].empty())adj[points[x].back().first].emplace_back(S,points[x].back().second-h);
    		points[x].emplace_back(S,h);
    		return S++;
    	};
    	vector<pair<int,int>> sorted_buildings;
    	for(int i=0;i<n;i++)sorted_buildings.emplace_back(h[i],i);
    	sort(sorted_buildings.rbegin(),sorted_buildings.rend());
    	auto iterb = sorted_buildings.begin();
    	set<int> active;
    	for(int i=0;i<m;i++){
    		auto [height,left,right] = skywalks[i];
    		while(iterb!=sorted_buildings.end() and iterb->first>=height)active.insert((iterb++)->second);
    		auto last_point = add_point(left,height);
    		auto last_x = x[left];
    		for(auto iter=active.upper_bound(left);true;iter++){
    			int j = *iter;
    			auto curr_point = add_point(j,height);
    			adj[curr_point].emplace_back(last_point,x[j]-last_x);
    			adj[last_point].emplace_back(curr_point,x[j]-last_x);
    			last_point=curr_point;
    			last_x=x[j];
    			if(*iter==right)break;
    		}
    	}
    	for(int i=0;i<n;i++)add_point(i,0);
    	priority_queue<pair<long long,int>> q;
    	vector<bool> visited(S);
    	s = points[s].back().first;
    	g = points[g].back().first;
    	q.emplace(0,s);
    	while(!q.empty()) {
    		auto [dist,idx] = q.top();q.pop();dist=-dist;
    		if(visited[idx])continue;
    		visited[idx]=true;
    		if(idx==g)return dist;
    		for(auto&[v,c]:adj[idx])if(!visited[v])q.emplace(-dist-c,v);
    	}
    	return -1;
    }
     
    long long min_distance(vector<int> x,vector<int> h,vector<int> l,
    					   vector<int> r,vector<int> y,int s,int g){
    	int n = x.size();
    	if(s!=0 or g!=n-1)return min_distance2(x,h,l,r,y,s,g);
    	int m = l.size();
    	vector<vector<int>> starters(n);
    	vector<vector<int>> ends(n);
    	for(int i=0;i<m;i++) {
    		starters[l[i]].emplace_back(y[i]);
    		ends[r[i]].emplace_back(y[i]);
    	}
    	multiset<pair<int,long long>> offers;
    	ends[0].emplace_back(0);
    	offers.emplace(0,0);
    	for(int i=0;i<n-1;i++) {
    		for(int&ht:starters[i]) {
    			auto iter = offers.lower_bound({ht,0});
    			long long bestopt = INF;
    			if(iter!=offers.end()) {
    				// try
    				bestopt=min(bestopt,iter->first-ht + iter->second);
    			}
    			if(iter!=offers.begin()) {
    				--iter;
    				// try
    				bestopt=min(bestopt,ht-iter->first+iter->second);
    			}
    			offers.emplace(ht,bestopt);
    		}
    		for(int&ht:ends[i]) {
    			offers.erase(offers.lower_bound({ht,0}));
    		}
    	}
    	if(offers.empty())return -1;
    	long long ans = x[g]-x[s]+offers.begin()->second+offers.begin()->first;
    	if(ans>=INF)return -1;
    	return ans;
    }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 440 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 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 0 ms 344 KB Output is correct
17 Correct 0 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 192 ms 67860 KB Output is correct
4 Correct 478 ms 85164 KB Output is correct
5 Correct 261 ms 74932 KB Output is correct
6 Correct 223 ms 73768 KB Output is correct
7 Correct 275 ms 74676 KB Output is correct
8 Correct 270 ms 83800 KB Output is correct
9 Correct 304 ms 73612 KB Output is correct
10 Correct 596 ms 130220 KB Output is correct
11 Correct 178 ms 44984 KB Output is correct
12 Correct 49 ms 19144 KB Output is correct
13 Correct 59 ms 19284 KB Output is correct
14 Correct 130 ms 46528 KB Output is correct
15 Correct 126 ms 45760 KB Output is correct
16 Correct 127 ms 44224 KB Output is correct
17 Correct 106 ms 42940 KB Output is correct
18 Correct 64 ms 18388 KB Output is correct
19 Correct 5 ms 2452 KB Output is correct
20 Correct 64 ms 24004 KB Output is correct
21 Correct 44 ms 14708 KB Output is correct
22 Correct 47 ms 18260 KB Output is correct
23 Correct 66 ms 19916 KB Output is correct
24 Correct 53 ms 17436 KB Output is correct
25 Correct 44 ms 15700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3672 KB Output is correct
2 Correct 51 ms 5964 KB Output is correct
3 Correct 58 ms 7248 KB Output is correct
4 Correct 81 ms 17104 KB Output is correct
5 Correct 119 ms 21584 KB Output is correct
6 Correct 107 ms 19536 KB Output is correct
7 Correct 43 ms 13648 KB Output is correct
8 Correct 58 ms 19280 KB Output is correct
9 Correct 98 ms 20940 KB Output is correct
10 Correct 63 ms 19112 KB Output is correct
11 Correct 8 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3672 KB Output is correct
2 Correct 51 ms 5964 KB Output is correct
3 Correct 58 ms 7248 KB Output is correct
4 Correct 81 ms 17104 KB Output is correct
5 Correct 119 ms 21584 KB Output is correct
6 Correct 107 ms 19536 KB Output is correct
7 Correct 43 ms 13648 KB Output is correct
8 Correct 58 ms 19280 KB Output is correct
9 Correct 98 ms 20940 KB Output is correct
10 Correct 63 ms 19112 KB Output is correct
11 Correct 8 ms 4188 KB Output is correct
12 Correct 57 ms 7248 KB Output is correct
13 Correct 85 ms 17236 KB Output is correct
14 Correct 123 ms 21584 KB Output is correct
15 Correct 65 ms 17088 KB Output is correct
16 Correct 67 ms 17236 KB Output is correct
17 Correct 66 ms 17236 KB Output is correct
18 Correct 72 ms 16980 KB Output is correct
19 Correct 67 ms 17340 KB Output is correct
20 Correct 46 ms 13648 KB Output is correct
21 Correct 18 ms 8784 KB Output is correct
22 Correct 77 ms 14772 KB Output is correct
23 Correct 62 ms 15440 KB Output is correct
24 Correct 54 ms 16724 KB Output is correct
25 Correct 52 ms 15284 KB Output is correct
26 Correct 57 ms 19356 KB Output is correct
27 Correct 101 ms 21072 KB Output is correct
28 Correct 102 ms 16724 KB Output is correct
29 Correct 97 ms 19628 KB Output is correct
30 Correct 42 ms 13624 KB Output is correct
31 Correct 93 ms 20908 KB Output is correct
32 Correct 53 ms 16980 KB Output is correct
33 Correct 57 ms 18796 KB Output is correct
34 Correct 74 ms 17748 KB Output is correct
35 Correct 54 ms 16980 KB Output is correct
36 Correct 83 ms 16208 KB Output is correct
37 Correct 93 ms 14928 KB Output is correct
38 Correct 46 ms 18252 KB Output is correct
39 Correct 68 ms 19728 KB Output is correct
40 Correct 52 ms 17300 KB Output is correct
41 Correct 45 ms 15880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 440 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 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 0 ms 344 KB Output is correct
17 Correct 0 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 192 ms 67860 KB Output is correct
21 Correct 478 ms 85164 KB Output is correct
22 Correct 261 ms 74932 KB Output is correct
23 Correct 223 ms 73768 KB Output is correct
24 Correct 275 ms 74676 KB Output is correct
25 Correct 270 ms 83800 KB Output is correct
26 Correct 304 ms 73612 KB Output is correct
27 Correct 596 ms 130220 KB Output is correct
28 Correct 178 ms 44984 KB Output is correct
29 Correct 49 ms 19144 KB Output is correct
30 Correct 59 ms 19284 KB Output is correct
31 Correct 130 ms 46528 KB Output is correct
32 Correct 126 ms 45760 KB Output is correct
33 Correct 127 ms 44224 KB Output is correct
34 Correct 106 ms 42940 KB Output is correct
35 Correct 64 ms 18388 KB Output is correct
36 Correct 5 ms 2452 KB Output is correct
37 Correct 64 ms 24004 KB Output is correct
38 Correct 44 ms 14708 KB Output is correct
39 Correct 47 ms 18260 KB Output is correct
40 Correct 66 ms 19916 KB Output is correct
41 Correct 53 ms 17436 KB Output is correct
42 Correct 44 ms 15700 KB Output is correct
43 Correct 15 ms 3672 KB Output is correct
44 Correct 51 ms 5964 KB Output is correct
45 Correct 58 ms 7248 KB Output is correct
46 Correct 81 ms 17104 KB Output is correct
47 Correct 119 ms 21584 KB Output is correct
48 Correct 107 ms 19536 KB Output is correct
49 Correct 43 ms 13648 KB Output is correct
50 Correct 58 ms 19280 KB Output is correct
51 Correct 98 ms 20940 KB Output is correct
52 Correct 63 ms 19112 KB Output is correct
53 Correct 8 ms 4188 KB Output is correct
54 Correct 57 ms 7248 KB Output is correct
55 Correct 85 ms 17236 KB Output is correct
56 Correct 123 ms 21584 KB Output is correct
57 Correct 65 ms 17088 KB Output is correct
58 Correct 67 ms 17236 KB Output is correct
59 Correct 66 ms 17236 KB Output is correct
60 Correct 72 ms 16980 KB Output is correct
61 Correct 67 ms 17340 KB Output is correct
62 Correct 46 ms 13648 KB Output is correct
63 Correct 18 ms 8784 KB Output is correct
64 Correct 77 ms 14772 KB Output is correct
65 Correct 62 ms 15440 KB Output is correct
66 Correct 54 ms 16724 KB Output is correct
67 Correct 52 ms 15284 KB Output is correct
68 Correct 57 ms 19356 KB Output is correct
69 Correct 101 ms 21072 KB Output is correct
70 Correct 102 ms 16724 KB Output is correct
71 Correct 97 ms 19628 KB Output is correct
72 Correct 42 ms 13624 KB Output is correct
73 Correct 93 ms 20908 KB Output is correct
74 Correct 53 ms 16980 KB Output is correct
75 Correct 57 ms 18796 KB Output is correct
76 Correct 74 ms 17748 KB Output is correct
77 Correct 54 ms 16980 KB Output is correct
78 Correct 83 ms 16208 KB Output is correct
79 Correct 93 ms 14928 KB Output is correct
80 Correct 46 ms 18252 KB Output is correct
81 Correct 68 ms 19728 KB Output is correct
82 Correct 52 ms 17300 KB Output is correct
83 Correct 45 ms 15880 KB Output is correct
84 Correct 33 ms 11980 KB Output is correct
85 Runtime error 2477 ms 1048576 KB Execution killed with signal 9
86 Halted 0 ms 0 KB -