답안 #1038965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038965 2024-07-30T10:09:13 Z parsadox2 Sky Walking (IOI19_walk) C++17
24 / 100
3534 ms 1048576 KB
#include "walk.h"
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;

const int N = 1e5 + 10;
const long long inf = 1e18;

int n , m , a[N] , pos[N];
vector <int> all[N];
vector <long long> dis[N];
vector <bool> marked[N];
vector <vector<pair<pair<int , int> , int>>> adj[N];

struct bridge{
	int l , r , y;
};
vector <bridge> vec;

bool cmp(bridge aa , bridge bb)
{
	return aa.y < bb.y;
}

struct SEG{
	int mx[N << 2];
	void Build(int node = 1 , int nl = 0 , int nr = n)
	{
		if(nr - nl == 1)
		{
			mx[node] = a[nl];
			return;
		}
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		Build(lc , nl , mid);  Build(rc , mid , nr);
		mx[node] = max(mx[lc] , mx[rc]);
	}
	int Get(int id , int val , int node = 1 , int nl = 0 , int nr = n)
	{
		if(nr <= id || mx[node] < val)
			return -1;
		if(nr - nl == 1)
			return nl;
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		int tmp = Get(id , val , lc , nl , mid);
		if(tmp == -1)
			return tmp = Get(id , val , rc , mid , nr);
		return tmp;
	}
} seg;

void Add(int l , int r , int y)
{
	int now = l;
	all[now].push_back(y);
	adj[now].emplace_back();
	while(now != r)
	{
		int id = seg.Get(now + 1 , y);
		all[id].push_back(y);
		adj[id].emplace_back();
		adj[now].back().push_back(make_pair(make_pair(id , all[id].size() - 1) , pos[id] - pos[now]));
		adj[id].back().push_back(make_pair(make_pair(now , all[now].size() - 1) , pos[id] - pos[now]));
		now = id;
	}
}

void Dij()
{
	priority_queue <pair<long long , pair<int , int>>> pq;
	for(int i = 0 ; i < n ; i++)  for(int j = 0 ; j < all[i].size() ; j++)
		pq.push(make_pair(-dis[i][j] , make_pair(i , j)));
	while(!pq.empty())
	{
		auto now = pq.top();
		pq.pop();
		long long D = abs(now.F);
		int x = now.S.F , y = now.S.S;
		if(marked[x][y])
			continue;
		//cout << x << " " << y << " ::::  " << D << endl;
		marked[x][y] = true;
		for(auto u : adj[x][y])  if(dis[u.F.F][u.F.S] > D + u.S)
		{
			dis[u.F.F][u.F.S] = D + u.S;
			pq.push(make_pair(-dis[u.F.F][u.F.S] , u.F));
		}
	}
}

long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g) {
	n = x.size();
	m = l.size();
	for(int i = 0 ; i < n ; i++)
	{
		a[i] = h[i];
		pos[i] = x[i];
	}
	for(int i = 0 ; i < m ; i++)
	{
		vec.push_back({l[i] , r[i] , y[i]});
	}
	sort(vec.begin() , vec.end() , cmp);
	seg.Build();
	for(auto u : vec)
	{
		Add(u.l , u.r , u.y);
	}
	for(int i = 0 ; i < n ; i++)  for(int j = 0 ; j + 1 < all[i].size() ; j++)
	{
		adj[i][j].push_back(make_pair(make_pair(i , j + 1) , all[i][j + 1] - all[i][j]));
		adj[i][j + 1].push_back(make_pair(make_pair(i , j) , all[i][j + 1] - all[i][j]));
	}
	/*for(int i = 0 ; i < n ; i++)  for(int j = 0 ; j < all[i].size() ; j++)
	{
		cout << i << " " << j << " : " << all[i][j] << endl;
		for(auto u : adj[i][j])
			cout << u.F.F << " " << u.F.S << " " << u.S << endl;
	}*/
	for(int i = 0 ; i < n ; i++)
	{
		dis[i].resize(all[i].size() , inf);
		marked[i].resize(all[i].size());
	}
	for(int i = 0 ; i < all[s].size() ; i++)
		dis[s][i] = all[s][i];
	Dij();
	long long res = inf;
	for(int i = 0 ; i < all[g].size() ; i++)
		res = min(res , dis[g][i] + all[g][i]);
	if(res == inf)
		res = -1;
	return res;
}

Compilation message

walk.cpp: In function 'void Dij()':
walk.cpp:73:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for(int i = 0 ; i < n ; i++)  for(int j = 0 ; j < all[i].size() ; j++)
      |                                                ~~^~~~~~~~~~~~~~~
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:111:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |  for(int i = 0 ; i < n ; i++)  for(int j = 0 ; j + 1 < all[i].size() ; j++)
      |                                                ~~~~~~^~~~~~~~~~~~~~~
walk.cpp:127:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |  for(int i = 0 ; i < all[s].size() ; i++)
      |                  ~~^~~~~~~~~~~~~~~
walk.cpp:131:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |  for(int i = 0 ; i < all[g].size() ; i++)
      |                  ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 4 ms 11392 KB Output is correct
3 Correct 5 ms 11356 KB Output is correct
4 Correct 4 ms 11356 KB Output is correct
5 Correct 5 ms 11356 KB Output is correct
6 Correct 5 ms 11356 KB Output is correct
7 Correct 4 ms 11356 KB Output is correct
8 Correct 4 ms 11356 KB Output is correct
9 Correct 4 ms 11356 KB Output is correct
10 Correct 4 ms 11356 KB Output is correct
11 Correct 4 ms 11356 KB Output is correct
12 Correct 4 ms 11412 KB Output is correct
13 Correct 5 ms 11284 KB Output is correct
14 Correct 4 ms 11356 KB Output is correct
15 Correct 4 ms 11356 KB Output is correct
16 Correct 4 ms 11308 KB Output is correct
17 Correct 5 ms 11356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 4 ms 11356 KB Output is correct
3 Correct 511 ms 115648 KB Output is correct
4 Correct 621 ms 121536 KB Output is correct
5 Correct 321 ms 109300 KB Output is correct
6 Correct 308 ms 91692 KB Output is correct
7 Correct 332 ms 109756 KB Output is correct
8 Correct 638 ms 138172 KB Output is correct
9 Correct 403 ms 108996 KB Output is correct
10 Correct 897 ms 156544 KB Output is correct
11 Correct 281 ms 68908 KB Output is correct
12 Correct 139 ms 51544 KB Output is correct
13 Correct 751 ms 145600 KB Output is correct
14 Correct 129 ms 51396 KB Output is correct
15 Correct 135 ms 50440 KB Output is correct
16 Correct 157 ms 51652 KB Output is correct
17 Correct 156 ms 50632 KB Output is correct
18 Correct 106 ms 48576 KB Output is correct
19 Correct 7 ms 14684 KB Output is correct
20 Correct 74 ms 30732 KB Output is correct
21 Correct 142 ms 48092 KB Output is correct
22 Correct 137 ms 50120 KB Output is correct
23 Correct 161 ms 60304 KB Output is correct
24 Correct 151 ms 49796 KB Output is correct
25 Correct 153 ms 51144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 30664 KB Output is correct
2 Correct 3534 ms 678928 KB Output is correct
3 Runtime error 2091 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 30664 KB Output is correct
2 Correct 3534 ms 678928 KB Output is correct
3 Runtime error 2091 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 4 ms 11392 KB Output is correct
3 Correct 5 ms 11356 KB Output is correct
4 Correct 4 ms 11356 KB Output is correct
5 Correct 5 ms 11356 KB Output is correct
6 Correct 5 ms 11356 KB Output is correct
7 Correct 4 ms 11356 KB Output is correct
8 Correct 4 ms 11356 KB Output is correct
9 Correct 4 ms 11356 KB Output is correct
10 Correct 4 ms 11356 KB Output is correct
11 Correct 4 ms 11356 KB Output is correct
12 Correct 4 ms 11412 KB Output is correct
13 Correct 5 ms 11284 KB Output is correct
14 Correct 4 ms 11356 KB Output is correct
15 Correct 4 ms 11356 KB Output is correct
16 Correct 4 ms 11308 KB Output is correct
17 Correct 5 ms 11356 KB Output is correct
18 Correct 5 ms 11356 KB Output is correct
19 Correct 4 ms 11356 KB Output is correct
20 Correct 511 ms 115648 KB Output is correct
21 Correct 621 ms 121536 KB Output is correct
22 Correct 321 ms 109300 KB Output is correct
23 Correct 308 ms 91692 KB Output is correct
24 Correct 332 ms 109756 KB Output is correct
25 Correct 638 ms 138172 KB Output is correct
26 Correct 403 ms 108996 KB Output is correct
27 Correct 897 ms 156544 KB Output is correct
28 Correct 281 ms 68908 KB Output is correct
29 Correct 139 ms 51544 KB Output is correct
30 Correct 751 ms 145600 KB Output is correct
31 Correct 129 ms 51396 KB Output is correct
32 Correct 135 ms 50440 KB Output is correct
33 Correct 157 ms 51652 KB Output is correct
34 Correct 156 ms 50632 KB Output is correct
35 Correct 106 ms 48576 KB Output is correct
36 Correct 7 ms 14684 KB Output is correct
37 Correct 74 ms 30732 KB Output is correct
38 Correct 142 ms 48092 KB Output is correct
39 Correct 137 ms 50120 KB Output is correct
40 Correct 161 ms 60304 KB Output is correct
41 Correct 151 ms 49796 KB Output is correct
42 Correct 153 ms 51144 KB Output is correct
43 Correct 61 ms 30664 KB Output is correct
44 Correct 3534 ms 678928 KB Output is correct
45 Runtime error 2091 ms 1048576 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -