답안 #286594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286594 2020-08-30T15:09:50 Z tmwilliamlin168 Sky Walking (IOI19_walk) C++14
100 / 100
1962 ms 144956 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=1e5, mxT=1e6;
int n, m, pg[mxN], t, ua, ub;
vector<int> ta[mxN], tr[mxN];
ll d[mxT];
vector<ar<ll, 2>> adj[mxT];

ll min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int a, int b) {
	n=x.size();
	m=l.size();
	vector<vector<int>> v(n);
	v[a].push_back(0);
	v[b].push_back(0);
	for(int _ : {1, 0}) {
		for(int i=0; i<m; ++i) {
			ta[l[i]].push_back(i);
			tr[r[i]].push_back(i);
		}
		set<ar<int, 2>> s;
		for(int i=0; i<n; ++i) {
			vector<ar<int, 2>> w;
			for(pg[i]=i-1; ~pg[i]&&h[pg[i]]<=h[i]; pg[i]=pg[pg[i]]) {
				auto it=s.lower_bound({h[pg[i]]});
				if(it!=s.end()&&(*it)[0]<=h[i])
					w.push_back(*it);
			}
			for(int j : ta[i])
				s.insert({y[j], j});
			for(auto a : w) {
				v[i].push_back(a[0]);
				auto it=s.upper_bound(a);
				if(it!=s.end()&&(*it)[0]<=h[i])
					v[i].push_back((*it)[0]);
			}
			for(int j : ta[i]) {
				v[i].push_back(y[j]);
				auto it=s.upper_bound({y[j], j});
				if(it!=s.end()&&(*it)[0]<=h[i])
					v[i].push_back((*it)[0]);
				if(--it!=s.begin())
					v[i].push_back((*--it)[0]);
			}
			if(_&&(i==a||i==b)&&s.size()&&(*s.begin())[0]<=h[i])
				v[i].push_back((*s.begin())[0]);
			for(int j : tr[i])
				s.erase({y[j], j});
			ta[i].clear();
			tr[i].clear();
		}
		reverse(h.begin(), h.end());
		for(int i=0; i<m; ++i)
			tie(l[i], r[i])=make_pair(n-1-r[i], n-1-l[i]);
		reverse(v.begin(), v.end());
	}
	unordered_map<int, int> m1;
	unordered_map<int, ar<int, 3>> m2;
	for(int i=0; i<m; ++i)
		ta[l[i]].push_back(i);
	for(int i=0; i<n; t+=v[i++].size()) {
		if(i==a)
			ua=t;
		if(i==b)
			ub=t;
		for(int j : ta[i])
			m1[y[j]]=r[j]+1;
		sort(v[i].begin(), v[i].end());
		v[i].resize(unique(v[i].begin(), v[i].end())-v[i].begin());
		for(int j=0; j+1<v[i].size(); ++j) {
			adj[t+j].push_back({v[i][j+1]-v[i][j], t+j+1});
			adj[t+j+1].push_back({v[i][j+1]-v[i][j], t+j});
		}
//		cout << i << endl;
		for(int j=0; j<v[i].size(); ++j) {
//			cout << v[i][j] << " ";
			auto a=m2[v[i][j]];
			if(a[2]>i) {
				adj[a[0]].push_back({x[i]-x[a[1]], t+j});
				adj[t+j].push_back({x[i]-x[a[1]], a[0]});
			}
			m2[v[i][j]]={t+j, i, m1[v[i][j]]};
		}
//		cout << endl;
	}
	memset(d, 0x3f, 8*t);
	priority_queue<ar<ll, 2>, vector<ar<ll, 2>>, greater<ar<ll, 2>>> pq;
	d[ua]=0;
	pq.push({0, ua});
	while(pq.size()) {
		ar<ll, 2> u=pq.top();
		pq.pop();
		if(u[0]>d[u[1]])
			continue;
//		cout << u[1] << " " << u[0] << endl;
		for(auto v : adj[u[1]]) {
			if(d[v[1]]>u[0]+v[0]) {
				d[v[1]]=u[0]+v[0];
				pq.push({d[v[1]], v[1]});
			}
		}
	}
	return d[ub]>2e14?-1:d[ub];
}

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:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for(int j=0; j+1<v[i].size(); ++j) {
      |                ~~~^~~~~~~~~~~~
walk.cpp:79:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for(int j=0; j<v[i].size(); ++j) {
      |                ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 28544 KB Output is correct
2 Correct 20 ms 28544 KB Output is correct
3 Correct 20 ms 28544 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 20 ms 28544 KB Output is correct
6 Correct 20 ms 28544 KB Output is correct
7 Correct 20 ms 28636 KB Output is correct
8 Correct 19 ms 28544 KB Output is correct
9 Correct 20 ms 28544 KB Output is correct
10 Correct 19 ms 28544 KB Output is correct
11 Correct 19 ms 28544 KB Output is correct
12 Correct 20 ms 28544 KB Output is correct
13 Correct 21 ms 28544 KB Output is correct
14 Correct 19 ms 28544 KB Output is correct
15 Correct 20 ms 28544 KB Output is correct
16 Correct 20 ms 28544 KB Output is correct
17 Correct 20 ms 28544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 28544 KB Output is correct
2 Correct 20 ms 28544 KB Output is correct
3 Correct 532 ms 82592 KB Output is correct
4 Correct 645 ms 93508 KB Output is correct
5 Correct 429 ms 77120 KB Output is correct
6 Correct 460 ms 73972 KB Output is correct
7 Correct 430 ms 77248 KB Output is correct
8 Correct 590 ms 87144 KB Output is correct
9 Correct 581 ms 89628 KB Output is correct
10 Correct 730 ms 102720 KB Output is correct
11 Correct 484 ms 74560 KB Output is correct
12 Correct 380 ms 64320 KB Output is correct
13 Correct 642 ms 98240 KB Output is correct
14 Correct 474 ms 63936 KB Output is correct
15 Correct 403 ms 63224 KB Output is correct
16 Correct 335 ms 61432 KB Output is correct
17 Correct 339 ms 60156 KB Output is correct
18 Correct 446 ms 69340 KB Output is correct
19 Correct 33 ms 30336 KB Output is correct
20 Correct 198 ms 47336 KB Output is correct
21 Correct 268 ms 58744 KB Output is correct
22 Correct 284 ms 60276 KB Output is correct
23 Correct 479 ms 73060 KB Output is correct
24 Correct 294 ms 60920 KB Output is correct
25 Correct 286 ms 59928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 38776 KB Output is correct
2 Correct 709 ms 95524 KB Output is correct
3 Correct 791 ms 97216 KB Output is correct
4 Correct 1006 ms 106816 KB Output is correct
5 Correct 1258 ms 106908 KB Output is correct
6 Correct 1191 ms 104100 KB Output is correct
7 Correct 442 ms 72592 KB Output is correct
8 Correct 364 ms 64320 KB Output is correct
9 Correct 1091 ms 102504 KB Output is correct
10 Correct 387 ms 72804 KB Output is correct
11 Correct 37 ms 31360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 38776 KB Output is correct
2 Correct 709 ms 95524 KB Output is correct
3 Correct 791 ms 97216 KB Output is correct
4 Correct 1006 ms 106816 KB Output is correct
5 Correct 1258 ms 106908 KB Output is correct
6 Correct 1191 ms 104100 KB Output is correct
7 Correct 442 ms 72592 KB Output is correct
8 Correct 364 ms 64320 KB Output is correct
9 Correct 1091 ms 102504 KB Output is correct
10 Correct 387 ms 72804 KB Output is correct
11 Correct 37 ms 31360 KB Output is correct
12 Correct 815 ms 100500 KB Output is correct
13 Correct 1022 ms 137792 KB Output is correct
14 Correct 1779 ms 141116 KB Output is correct
15 Correct 767 ms 88584 KB Output is correct
16 Correct 1162 ms 122252 KB Output is correct
17 Correct 1226 ms 133388 KB Output is correct
18 Correct 772 ms 88368 KB Output is correct
19 Correct 1136 ms 121356 KB Output is correct
20 Correct 810 ms 103184 KB Output is correct
21 Correct 274 ms 59640 KB Output is correct
22 Correct 549 ms 94400 KB Output is correct
23 Correct 490 ms 85532 KB Output is correct
24 Correct 476 ms 70976 KB Output is correct
25 Correct 472 ms 82112 KB Output is correct
26 Correct 489 ms 63936 KB Output is correct
27 Correct 1745 ms 133692 KB Output is correct
28 Correct 817 ms 137924 KB Output is correct
29 Correct 1660 ms 138912 KB Output is correct
30 Correct 735 ms 99088 KB Output is correct
31 Correct 1603 ms 134528 KB Output is correct
32 Correct 320 ms 63344 KB Output is correct
33 Correct 334 ms 65008 KB Output is correct
34 Correct 414 ms 69548 KB Output is correct
35 Correct 494 ms 75384 KB Output is correct
36 Correct 344 ms 62968 KB Output is correct
37 Correct 261 ms 56056 KB Output is correct
38 Correct 280 ms 57072 KB Output is correct
39 Correct 463 ms 70424 KB Output is correct
40 Correct 285 ms 57976 KB Output is correct
41 Correct 294 ms 57264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 28544 KB Output is correct
2 Correct 20 ms 28544 KB Output is correct
3 Correct 20 ms 28544 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 20 ms 28544 KB Output is correct
6 Correct 20 ms 28544 KB Output is correct
7 Correct 20 ms 28636 KB Output is correct
8 Correct 19 ms 28544 KB Output is correct
9 Correct 20 ms 28544 KB Output is correct
10 Correct 19 ms 28544 KB Output is correct
11 Correct 19 ms 28544 KB Output is correct
12 Correct 20 ms 28544 KB Output is correct
13 Correct 21 ms 28544 KB Output is correct
14 Correct 19 ms 28544 KB Output is correct
15 Correct 20 ms 28544 KB Output is correct
16 Correct 20 ms 28544 KB Output is correct
17 Correct 20 ms 28544 KB Output is correct
18 Correct 19 ms 28544 KB Output is correct
19 Correct 20 ms 28544 KB Output is correct
20 Correct 532 ms 82592 KB Output is correct
21 Correct 645 ms 93508 KB Output is correct
22 Correct 429 ms 77120 KB Output is correct
23 Correct 460 ms 73972 KB Output is correct
24 Correct 430 ms 77248 KB Output is correct
25 Correct 590 ms 87144 KB Output is correct
26 Correct 581 ms 89628 KB Output is correct
27 Correct 730 ms 102720 KB Output is correct
28 Correct 484 ms 74560 KB Output is correct
29 Correct 380 ms 64320 KB Output is correct
30 Correct 642 ms 98240 KB Output is correct
31 Correct 474 ms 63936 KB Output is correct
32 Correct 403 ms 63224 KB Output is correct
33 Correct 335 ms 61432 KB Output is correct
34 Correct 339 ms 60156 KB Output is correct
35 Correct 446 ms 69340 KB Output is correct
36 Correct 33 ms 30336 KB Output is correct
37 Correct 198 ms 47336 KB Output is correct
38 Correct 268 ms 58744 KB Output is correct
39 Correct 284 ms 60276 KB Output is correct
40 Correct 479 ms 73060 KB Output is correct
41 Correct 294 ms 60920 KB Output is correct
42 Correct 286 ms 59928 KB Output is correct
43 Correct 108 ms 38776 KB Output is correct
44 Correct 709 ms 95524 KB Output is correct
45 Correct 791 ms 97216 KB Output is correct
46 Correct 1006 ms 106816 KB Output is correct
47 Correct 1258 ms 106908 KB Output is correct
48 Correct 1191 ms 104100 KB Output is correct
49 Correct 442 ms 72592 KB Output is correct
50 Correct 364 ms 64320 KB Output is correct
51 Correct 1091 ms 102504 KB Output is correct
52 Correct 387 ms 72804 KB Output is correct
53 Correct 37 ms 31360 KB Output is correct
54 Correct 815 ms 100500 KB Output is correct
55 Correct 1022 ms 137792 KB Output is correct
56 Correct 1779 ms 141116 KB Output is correct
57 Correct 767 ms 88584 KB Output is correct
58 Correct 1162 ms 122252 KB Output is correct
59 Correct 1226 ms 133388 KB Output is correct
60 Correct 772 ms 88368 KB Output is correct
61 Correct 1136 ms 121356 KB Output is correct
62 Correct 810 ms 103184 KB Output is correct
63 Correct 274 ms 59640 KB Output is correct
64 Correct 549 ms 94400 KB Output is correct
65 Correct 490 ms 85532 KB Output is correct
66 Correct 476 ms 70976 KB Output is correct
67 Correct 472 ms 82112 KB Output is correct
68 Correct 489 ms 63936 KB Output is correct
69 Correct 1745 ms 133692 KB Output is correct
70 Correct 817 ms 137924 KB Output is correct
71 Correct 1660 ms 138912 KB Output is correct
72 Correct 735 ms 99088 KB Output is correct
73 Correct 1603 ms 134528 KB Output is correct
74 Correct 320 ms 63344 KB Output is correct
75 Correct 334 ms 65008 KB Output is correct
76 Correct 414 ms 69548 KB Output is correct
77 Correct 494 ms 75384 KB Output is correct
78 Correct 344 ms 62968 KB Output is correct
79 Correct 261 ms 56056 KB Output is correct
80 Correct 280 ms 57072 KB Output is correct
81 Correct 463 ms 70424 KB Output is correct
82 Correct 285 ms 57976 KB Output is correct
83 Correct 294 ms 57264 KB Output is correct
84 Correct 98 ms 37372 KB Output is correct
85 Correct 811 ms 101824 KB Output is correct
86 Correct 1803 ms 144956 KB Output is correct
87 Correct 135 ms 45432 KB Output is correct
88 Correct 263 ms 59552 KB Output is correct
89 Correct 136 ms 45432 KB Output is correct
90 Correct 52 ms 33536 KB Output is correct
91 Correct 20 ms 28800 KB Output is correct
92 Correct 59 ms 34296 KB Output is correct
93 Correct 658 ms 92944 KB Output is correct
94 Correct 267 ms 59008 KB Output is correct
95 Correct 593 ms 100672 KB Output is correct
96 Correct 492 ms 88896 KB Output is correct
97 Correct 469 ms 74176 KB Output is correct
98 Correct 463 ms 85184 KB Output is correct
99 Correct 1962 ms 141980 KB Output is correct
100 Correct 1229 ms 143848 KB Output is correct
101 Correct 1688 ms 142112 KB Output is correct
102 Correct 712 ms 101520 KB Output is correct
103 Correct 339 ms 67240 KB Output is correct
104 Correct 339 ms 67828 KB Output is correct
105 Correct 431 ms 71860 KB Output is correct
106 Correct 394 ms 70272 KB Output is correct
107 Correct 453 ms 67580 KB Output is correct
108 Correct 95 ms 37496 KB Output is correct
109 Correct 1373 ms 124380 KB Output is correct
110 Correct 756 ms 122784 KB Output is correct
111 Correct 693 ms 122688 KB Output is correct
112 Correct 471 ms 75128 KB Output is correct
113 Correct 414 ms 70264 KB Output is correct