Submission #951060

# Submission time Handle Problem Language Result Execution time Memory
951060 2024-03-21T05:23:25 Z Trisanu_Das Sky Walking (IOI19_walk) C++17
100 / 100
1197 ms 146400 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});
		}
		for(int j=0; j<v[i].size(); ++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]]};
		}
	}
	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;
		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:78:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   for(int j=0; j<v[i].size(); ++j) {
      |                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 30040 KB Output is correct
2 Correct 7 ms 30044 KB Output is correct
3 Correct 7 ms 30044 KB Output is correct
4 Correct 7 ms 30044 KB Output is correct
5 Correct 7 ms 30296 KB Output is correct
6 Correct 7 ms 30296 KB Output is correct
7 Correct 7 ms 30300 KB Output is correct
8 Correct 7 ms 30300 KB Output is correct
9 Correct 7 ms 30300 KB Output is correct
10 Correct 7 ms 30300 KB Output is correct
11 Correct 8 ms 30296 KB Output is correct
12 Correct 7 ms 30300 KB Output is correct
13 Correct 7 ms 30300 KB Output is correct
14 Correct 7 ms 30248 KB Output is correct
15 Correct 7 ms 30296 KB Output is correct
16 Correct 7 ms 30300 KB Output is correct
17 Correct 7 ms 30296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 30040 KB Output is correct
2 Correct 7 ms 30044 KB Output is correct
3 Correct 338 ms 82604 KB Output is correct
4 Correct 424 ms 95520 KB Output is correct
5 Correct 237 ms 77040 KB Output is correct
6 Correct 252 ms 73844 KB Output is correct
7 Correct 231 ms 76916 KB Output is correct
8 Correct 391 ms 89040 KB Output is correct
9 Correct 324 ms 91708 KB Output is correct
10 Correct 446 ms 103900 KB Output is correct
11 Correct 294 ms 75832 KB Output is correct
12 Correct 200 ms 66516 KB Output is correct
13 Correct 431 ms 100044 KB Output is correct
14 Correct 258 ms 66280 KB Output is correct
15 Correct 218 ms 62476 KB Output is correct
16 Correct 162 ms 60848 KB Output is correct
17 Correct 173 ms 59648 KB Output is correct
18 Correct 315 ms 69976 KB Output is correct
19 Correct 15 ms 31832 KB Output is correct
20 Correct 109 ms 46632 KB Output is correct
21 Correct 131 ms 58196 KB Output is correct
22 Correct 145 ms 59216 KB Output is correct
23 Correct 290 ms 72208 KB Output is correct
24 Correct 180 ms 59948 KB Output is correct
25 Correct 159 ms 59444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 39356 KB Output is correct
2 Correct 476 ms 96792 KB Output is correct
3 Correct 471 ms 98364 KB Output is correct
4 Correct 646 ms 108356 KB Output is correct
5 Correct 812 ms 108500 KB Output is correct
6 Correct 756 ms 105988 KB Output is correct
7 Correct 281 ms 73592 KB Output is correct
8 Correct 200 ms 66516 KB Output is correct
9 Correct 714 ms 104648 KB Output is correct
10 Correct 256 ms 74648 KB Output is correct
11 Correct 16 ms 32348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 39356 KB Output is correct
2 Correct 476 ms 96792 KB Output is correct
3 Correct 471 ms 98364 KB Output is correct
4 Correct 646 ms 108356 KB Output is correct
5 Correct 812 ms 108500 KB Output is correct
6 Correct 756 ms 105988 KB Output is correct
7 Correct 281 ms 73592 KB Output is correct
8 Correct 200 ms 66516 KB Output is correct
9 Correct 714 ms 104648 KB Output is correct
10 Correct 256 ms 74648 KB Output is correct
11 Correct 16 ms 32348 KB Output is correct
12 Correct 495 ms 101156 KB Output is correct
13 Correct 574 ms 138692 KB Output is correct
14 Correct 1140 ms 141936 KB Output is correct
15 Correct 478 ms 89216 KB Output is correct
16 Correct 705 ms 123116 KB Output is correct
17 Correct 761 ms 132744 KB Output is correct
18 Correct 470 ms 89240 KB Output is correct
19 Correct 689 ms 122036 KB Output is correct
20 Correct 537 ms 103792 KB Output is correct
21 Correct 170 ms 60716 KB Output is correct
22 Correct 338 ms 95080 KB Output is correct
23 Correct 276 ms 84544 KB Output is correct
24 Correct 250 ms 71592 KB Output is correct
25 Correct 256 ms 81776 KB Output is correct
26 Correct 262 ms 66228 KB Output is correct
27 Correct 1108 ms 135772 KB Output is correct
28 Correct 484 ms 138300 KB Output is correct
29 Correct 1051 ms 140372 KB Output is correct
30 Correct 482 ms 100092 KB Output is correct
31 Correct 1058 ms 137088 KB Output is correct
32 Correct 187 ms 65852 KB Output is correct
33 Correct 195 ms 66772 KB Output is correct
34 Correct 254 ms 72184 KB Output is correct
35 Correct 292 ms 76296 KB Output is correct
36 Correct 180 ms 64432 KB Output is correct
37 Correct 131 ms 58168 KB Output is correct
38 Correct 155 ms 59280 KB Output is correct
39 Correct 278 ms 72128 KB Output is correct
40 Correct 154 ms 59968 KB Output is correct
41 Correct 156 ms 59532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 30040 KB Output is correct
2 Correct 7 ms 30044 KB Output is correct
3 Correct 7 ms 30044 KB Output is correct
4 Correct 7 ms 30044 KB Output is correct
5 Correct 7 ms 30296 KB Output is correct
6 Correct 7 ms 30296 KB Output is correct
7 Correct 7 ms 30300 KB Output is correct
8 Correct 7 ms 30300 KB Output is correct
9 Correct 7 ms 30300 KB Output is correct
10 Correct 7 ms 30300 KB Output is correct
11 Correct 8 ms 30296 KB Output is correct
12 Correct 7 ms 30300 KB Output is correct
13 Correct 7 ms 30300 KB Output is correct
14 Correct 7 ms 30248 KB Output is correct
15 Correct 7 ms 30296 KB Output is correct
16 Correct 7 ms 30300 KB Output is correct
17 Correct 7 ms 30296 KB Output is correct
18 Correct 7 ms 30040 KB Output is correct
19 Correct 7 ms 30044 KB Output is correct
20 Correct 338 ms 82604 KB Output is correct
21 Correct 424 ms 95520 KB Output is correct
22 Correct 237 ms 77040 KB Output is correct
23 Correct 252 ms 73844 KB Output is correct
24 Correct 231 ms 76916 KB Output is correct
25 Correct 391 ms 89040 KB Output is correct
26 Correct 324 ms 91708 KB Output is correct
27 Correct 446 ms 103900 KB Output is correct
28 Correct 294 ms 75832 KB Output is correct
29 Correct 200 ms 66516 KB Output is correct
30 Correct 431 ms 100044 KB Output is correct
31 Correct 258 ms 66280 KB Output is correct
32 Correct 218 ms 62476 KB Output is correct
33 Correct 162 ms 60848 KB Output is correct
34 Correct 173 ms 59648 KB Output is correct
35 Correct 315 ms 69976 KB Output is correct
36 Correct 15 ms 31832 KB Output is correct
37 Correct 109 ms 46632 KB Output is correct
38 Correct 131 ms 58196 KB Output is correct
39 Correct 145 ms 59216 KB Output is correct
40 Correct 290 ms 72208 KB Output is correct
41 Correct 180 ms 59948 KB Output is correct
42 Correct 159 ms 59444 KB Output is correct
43 Correct 62 ms 39356 KB Output is correct
44 Correct 476 ms 96792 KB Output is correct
45 Correct 471 ms 98364 KB Output is correct
46 Correct 646 ms 108356 KB Output is correct
47 Correct 812 ms 108500 KB Output is correct
48 Correct 756 ms 105988 KB Output is correct
49 Correct 281 ms 73592 KB Output is correct
50 Correct 200 ms 66516 KB Output is correct
51 Correct 714 ms 104648 KB Output is correct
52 Correct 256 ms 74648 KB Output is correct
53 Correct 16 ms 32348 KB Output is correct
54 Correct 495 ms 101156 KB Output is correct
55 Correct 574 ms 138692 KB Output is correct
56 Correct 1140 ms 141936 KB Output is correct
57 Correct 478 ms 89216 KB Output is correct
58 Correct 705 ms 123116 KB Output is correct
59 Correct 761 ms 132744 KB Output is correct
60 Correct 470 ms 89240 KB Output is correct
61 Correct 689 ms 122036 KB Output is correct
62 Correct 537 ms 103792 KB Output is correct
63 Correct 170 ms 60716 KB Output is correct
64 Correct 338 ms 95080 KB Output is correct
65 Correct 276 ms 84544 KB Output is correct
66 Correct 250 ms 71592 KB Output is correct
67 Correct 256 ms 81776 KB Output is correct
68 Correct 262 ms 66228 KB Output is correct
69 Correct 1108 ms 135772 KB Output is correct
70 Correct 484 ms 138300 KB Output is correct
71 Correct 1051 ms 140372 KB Output is correct
72 Correct 482 ms 100092 KB Output is correct
73 Correct 1058 ms 137088 KB Output is correct
74 Correct 187 ms 65852 KB Output is correct
75 Correct 195 ms 66772 KB Output is correct
76 Correct 254 ms 72184 KB Output is correct
77 Correct 292 ms 76296 KB Output is correct
78 Correct 180 ms 64432 KB Output is correct
79 Correct 131 ms 58168 KB Output is correct
80 Correct 155 ms 59280 KB Output is correct
81 Correct 278 ms 72128 KB Output is correct
82 Correct 154 ms 59968 KB Output is correct
83 Correct 156 ms 59532 KB Output is correct
84 Correct 56 ms 37968 KB Output is correct
85 Correct 509 ms 101140 KB Output is correct
86 Correct 1178 ms 146400 KB Output is correct
87 Correct 75 ms 46372 KB Output is correct
88 Correct 159 ms 61268 KB Output is correct
89 Correct 78 ms 46184 KB Output is correct
90 Correct 29 ms 34864 KB Output is correct
91 Correct 9 ms 30556 KB Output is correct
92 Correct 39 ms 35676 KB Output is correct
93 Correct 463 ms 94440 KB Output is correct
94 Correct 176 ms 60760 KB Output is correct
95 Correct 368 ms 101368 KB Output is correct
96 Correct 279 ms 88808 KB Output is correct
97 Correct 252 ms 75120 KB Output is correct
98 Correct 274 ms 85664 KB Output is correct
99 Correct 1197 ms 145720 KB Output is correct
100 Correct 803 ms 145404 KB Output is correct
101 Correct 1086 ms 144128 KB Output is correct
102 Correct 470 ms 103412 KB Output is correct
103 Correct 188 ms 69416 KB Output is correct
104 Correct 192 ms 69940 KB Output is correct
105 Correct 263 ms 74356 KB Output is correct
106 Correct 224 ms 72620 KB Output is correct
107 Correct 249 ms 69876 KB Output is correct
108 Correct 51 ms 38740 KB Output is correct
109 Correct 828 ms 125480 KB Output is correct
110 Correct 463 ms 125116 KB Output is correct
111 Correct 433 ms 125248 KB Output is correct
112 Correct 257 ms 76504 KB Output is correct
113 Correct 228 ms 71760 KB Output is correct