답안 #598591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598591 2022-07-18T14:35:12 Z yutabi Sky Walking (IOI19_walk) C++14
10 / 100
1575 ms 850700 KB
#include "walk.h"


#include <bits/stdc++.h>
using namespace std;


#define INF 1000000000000000007
#define pb push_back


typedef long long ll;
typedef pair <ll,ll> ii;





vector <vector <ii> > graph;

vector <ll> res;
priority_queue <ii> pq;
vector <bool> v;


long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g)
{
	int n=x.size();
	int m=l.size();

	vector <ii> last_added(n,ii(-1,-1));

	int k=0;

	vector <ii> build;
	vector <pair <ll,ii> > sky;

	for(int i=0;i<n;i++)
	{
		build.pb(ii(h[i],i));
	}

	for(int i=0;i<m;i++)
	{
		sky.pb(make_pair(y[i],ii(l[i],r[i])));
	}

	sort(build.begin(),build.end());
	sort(sky.rbegin(),sky.rend());

	set <int> builds;

	for(int i=0;i<m;i++)
	{
		while(build.size() && build.back().first>=sky[i].first)
		{
			builds.insert(build.back().second);

			build.pop_back();
		}

		auto it=builds.lower_bound(sky[i].second.first);

		int last=*it;

		ll height=sky[i].first;

		graph.pb({});

		if(last_added[last].first!=-1)
		{
			graph[last_added[last].first].pb(ii(k,last_added[last].second-height));
			graph[k].pb(ii(last_added[last].first,last_added[last].second-height));
		}

		last_added[last]=ii(k,height);

		k++;






		it++;

		while(it!=builds.end() && *it<=sky[i].second.second)
		{
			int curr=*it;

			graph.pb({});

			graph[k-1].pb(ii(k,x[curr]-x[last]));
			graph[k].pb(ii(k-1,x[curr]-x[last]));

			if(last_added[curr].first!=-1)
			{
				graph[last_added[curr].first].pb(ii(k,last_added[curr].second-height));
				graph[k].pb(ii(last_added[curr].first,last_added[curr].second-height));
			}

			last_added[curr]=ii(k,height);

			k++;

			last=curr;

			it++;
		}
	}

	int start_index;
	int end_index;

	for(int i=0;i<n;i++)
	{
		graph.pb({});

		if(last_added[i].first!=-1)
		{
			graph[last_added[i].first].pb(ii(k,last_added[i].second-0));
			graph[k].pb(ii(last_added[i].first,last_added[i].second-0));
		}

		if(s==i)
		{
			start_index=k;
		}

		if(g==i)
		{
			end_index=k;
		}

		k++;
	}


	res=vector <ll> (n*20,-1);

	v=vector <bool> (n*20,0);

	pq.push(ii(0,start_index));

	while(pq.size())
	{
		int index=pq.top().second;
		ll dist=-pq.top().first;

		pq.pop();

		if(v[index])
		{
			continue;
		}

		res[index]=dist;

		v[index]=1;

		for(int i=0;i<graph[index].size();i++)
		{
			if(v[graph[index][i].first]==0)
			{
				pq.push(ii(-(dist+graph[index][i].second),graph[index][i].first));
			}
		}
	}

	
	return res[end_index];
}

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:161:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  161 |   for(int i=0;i<graph[index].size();i++)
      |               ~^~~~~~~~~~~~~~~~~~~~
walk.cpp:171:22: warning: 'end_index' may be used uninitialized in this function [-Wmaybe-uninitialized]
  171 |  return res[end_index];
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Runtime error 303 ms 162560 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 17208 KB Output is correct
2 Runtime error 1575 ms 850700 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 17208 KB Output is correct
2 Runtime error 1575 ms 850700 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Runtime error 303 ms 162560 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -