답안 #433894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433894 2021-06-20T11:55:34 Z kostia244 Sky Walking (IOI19_walk) C++17
24 / 100
3961 ms 1048580 KB
#include "walk.h"
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;

ll min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int U, int V) {
	int n = x.size(), m = l.size();
	vector<vector<array<int, 2>>> g;
	vector<vector<int>> on(n+1);
	vector<int> col, lst(m, -1), start(n);
	for(int i = 0; i < m; i++) {
		on[l[i]].push_back(i);
		on[r[i]+1].push_back(-1-i);
	}
	set<array<int, 2>> hv;
	for(int i = 0; i < n; i++) {
		for(auto id : on[i]) {
			if(id < 0) {
				id = -id-1;
				hv.erase({y[id], id});
			} else
				hv.insert({y[id], id});
		}
		start[i] = g.size();
		g.push_back({});//(i, 0)
		col.push_back(i);
		int loh = 0;
		auto it = hv.begin();
		while(it != hv.end() && it->at(0) <= h[i]) {
			int id = it->at(1);
			g.back().push_back({g.size(), y[id]-loh});
			g.push_back({{g.size()-1, y[id]-loh}});
			//cout << g.size()-1 << " " << g.size()-2 << " " << y[id]-loh << endl;
			col.push_back(i);
			//cout << i << " " << id << "uwu\n";
			if(lst[id] != -1) {
				g[lst[id]].push_back({g.size()-1, x[i]-x[col[lst[id]]]});
				g.back().push_back({lst[id], x[i]-x[col[lst[id]]]});
			}
			lst[id] = g.size()-1;
			loh = y[id];
			it++;
		}	
	}
	U = start[U];
	V = start[V];
	priority_queue<array<ll, 2>> pq;
	vector<ll> dist(g.size(), 1ll<<60);
	auto enq = [&](int v, ll d) {
		//if(col[v] > 1) return;///REMOVE
		if(dist[v] <= d) return;
		dist[v] = d;
		pq.push({-dist[v], v});
	};
	//cout << U << " " << V << endl;
	for(enq(U, 0); !pq.empty();) {
		auto [di, v] = pq.top();
		pq.pop();
		di *= -1;
		if(di > dist[v]) continue;
		//cout << v << " at " << dist[v] << " ? " << col[v] << endl;
		if(v == V) return dist[v];
		for(auto [i, w] : g[v]) {
			//cout << v << " -> " << i << " " << w << endl;
			enq(i, di+w);
		}
	}
	//for(int i = 0; i < g.size(); i++) cout << col[i] << " "; cout << endl;
	//for(int i = 0; i < g.size(); i++) cout << dist[i] << " "; cout << endl;
	return -1;
}

Compilation message

walk.cpp: In function 'll min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:32:30: warning: narrowing conversion of 'g.std::vector<std::vector<std::array<int, 2> > >::size()' from 'std::vector<std::vector<std::array<int, 2> > >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   32 |    g.back().push_back({g.size(), y[id]-loh});
      |                        ~~~~~~^~
walk.cpp:33:26: warning: narrowing conversion of '(g.std::vector<std::vector<std::array<int, 2> > >::size() - 1)' from 'std::vector<std::vector<std::array<int, 2> > >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   33 |    g.push_back({{g.size()-1, y[id]-loh}});
      |                  ~~~~~~~~^~
walk.cpp:38:35: warning: narrowing conversion of '(g.std::vector<std::vector<std::array<int, 2> > >::size() - 1)' from 'std::vector<std::vector<std::array<int, 2> > >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   38 |     g[lst[id]].push_back({g.size()-1, x[i]-x[col[lst[id]]]});
      |                           ~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 259 ms 62980 KB Output is correct
4 Correct 465 ms 74088 KB Output is correct
5 Correct 257 ms 64412 KB Output is correct
6 Correct 253 ms 58712 KB Output is correct
7 Correct 296 ms 64508 KB Output is correct
8 Correct 363 ms 79440 KB Output is correct
9 Correct 309 ms 63036 KB Output is correct
10 Correct 594 ms 110788 KB Output is correct
11 Correct 222 ms 37640 KB Output is correct
12 Correct 176 ms 33380 KB Output is correct
13 Correct 519 ms 87776 KB Output is correct
14 Correct 182 ms 33000 KB Output is correct
15 Correct 180 ms 34020 KB Output is correct
16 Correct 199 ms 35952 KB Output is correct
17 Correct 180 ms 35276 KB Output is correct
18 Correct 194 ms 38924 KB Output is correct
19 Correct 8 ms 1928 KB Output is correct
20 Correct 78 ms 18800 KB Output is correct
21 Correct 169 ms 34808 KB Output is correct
22 Correct 151 ms 36548 KB Output is correct
23 Correct 238 ms 44756 KB Output is correct
24 Correct 169 ms 35980 KB Output is correct
25 Correct 179 ms 35308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 12292 KB Output is correct
2 Correct 2341 ms 426572 KB Output is correct
3 Runtime error 3961 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 12292 KB Output is correct
2 Correct 2341 ms 426572 KB Output is correct
3 Runtime error 3961 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 259 ms 62980 KB Output is correct
21 Correct 465 ms 74088 KB Output is correct
22 Correct 257 ms 64412 KB Output is correct
23 Correct 253 ms 58712 KB Output is correct
24 Correct 296 ms 64508 KB Output is correct
25 Correct 363 ms 79440 KB Output is correct
26 Correct 309 ms 63036 KB Output is correct
27 Correct 594 ms 110788 KB Output is correct
28 Correct 222 ms 37640 KB Output is correct
29 Correct 176 ms 33380 KB Output is correct
30 Correct 519 ms 87776 KB Output is correct
31 Correct 182 ms 33000 KB Output is correct
32 Correct 180 ms 34020 KB Output is correct
33 Correct 199 ms 35952 KB Output is correct
34 Correct 180 ms 35276 KB Output is correct
35 Correct 194 ms 38924 KB Output is correct
36 Correct 8 ms 1928 KB Output is correct
37 Correct 78 ms 18800 KB Output is correct
38 Correct 169 ms 34808 KB Output is correct
39 Correct 151 ms 36548 KB Output is correct
40 Correct 238 ms 44756 KB Output is correct
41 Correct 169 ms 35980 KB Output is correct
42 Correct 179 ms 35308 KB Output is correct
43 Correct 62 ms 12292 KB Output is correct
44 Correct 2341 ms 426572 KB Output is correct
45 Runtime error 3961 ms 1048580 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -