답안 #416770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416770 2021-06-02T22:08:40 Z peuch Sky Walking (IOI19_walk) C++17
0 / 100
183 ms 18332 KB
#include "walk.h"
#include<bits/stdc++.h>
using namespace std;
 
const int MAXN = 1e5 + 10;
const long long INF = 1e18;
 
map<pair<int, int>, int> node;
vector<long long> dist;
vector<int> marc;
vector<vector<long long> > ar, wg;
int cnt = -1;
 
struct event{
	int l, r, h;
	event(int _l = 0, int _r = 0, int _h = 0){
		l = _l, r = _r, h = _h;
	}
	bool operator < (event x) const {
		if(h == x.h) return r - l < x.r - x.l;
		return h > x.h;	
	}
};
 
vector<event> line;
 
void dijkstra(int ini);
 
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) {
	for(int i = 0; i < X.size(); i++)
		line.push_back(event(i, i, H[i]));
	for(int i = 0; i < L.size(); i++)
		line.push_back(event(L[i], R[i], Y[i]));
	sort(line.begin(), line.end());
	vector<int> last(X.size(), 0);
	for(int i = 0; i < line.size(); i++){
		int l = line[i].l, r = line[i].r, y = line[i].h;
		if(l == r) continue;
		if(node[make_pair(l, y)] == 0) {
			node[make_pair(l, y)] = ++cnt;
			ar.push_back(vector<long long>(0));
			wg.push_back(vector<long long>(0));
			dist.push_back(INF);
			marc.push_back(0);
			if(last[l] != 0) {
				ar[node[make_pair(l, y)]].push_back(node[make_pair(l, last[l])]);
				ar[node[make_pair(l, last[l])]].push_back(node[make_pair(l, y)]);
				wg[node[make_pair(l, y)]].push_back(abs(y - last[l]));
				wg[node[make_pair(l, last[l])]].push_back(abs(y - last[l]));
			}
			last[l] = y;
		}
		if(node[make_pair(r, y)] == 0) {
			node[make_pair(r, y)] = ++cnt;
			ar.push_back(vector<long long>(0));
			wg.push_back(vector<long long>(0));
			dist.push_back(INF);
			marc.push_back(0);
			if(last[r] != 0) {
				ar[node[make_pair(r, y)]].push_back(node[make_pair(r, last[r])]);
				ar[node[make_pair(r, last[r])]].push_back(node[make_pair(r, y)]);
				wg[node[make_pair(r, y)]].push_back(abs(y - last[r]));
				wg[node[make_pair(r, last[r])]].push_back(abs(y - last[r]));
			}
			last[r] = y;
		}
		
		ar[node[make_pair(l, y)]].push_back(node[make_pair(l, y)]);
		ar[node[make_pair(r, y)]].push_back(node[make_pair(r, y)]);
		wg[node[make_pair(l, y)]].push_back(abs(X[r] - X[l]));
		wg[node[make_pair(r, y)]].push_back(abs(X[r] - X[l]));
	}
	for(int i = 0; i < X.size(); i++){
		if(node[make_pair(i, 0)] == 0) {
			node[make_pair(i, 0)] = ++cnt;
			ar.push_back(vector<long long>(0));
			wg.push_back(vector<long long>(0));	
			dist.push_back(INF);
			marc.push_back(0);
			if(last[i] != 0) {
				ar[node[make_pair(i, 0)]].push_back(node[make_pair(i, last[i])]);
				ar[node[make_pair(i, last[i])]].push_back(node[make_pair(i, 0)]);
				wg[node[make_pair(i, 0)]].push_back(abs(0 - last[i]));
				wg[node[make_pair(i, last[i])]].push_back(abs(0 - last[i]));			
			}
			last[i] = 0;
		}
	}
	dijkstra(node[make_pair(S, 0)]);
	if(dist[node[make_pair(G, 0)]] >= INF) dist[node[make_pair(G, 0)]] = -1;
	return dist[node[make_pair(G, 0)]];
}
 
void dijkstra(int ini){
	dist[ini] = 0;
	set<pair<long long, int> > s;
	for(int i = 0; i <= cnt; i++)
		s.insert(make_pair(dist[i], i));
	while(!s.empty()){
		int cur = s.begin()->second;
		if(dist[cur] >= INF) break;
		marc[cur] = 1;
		s.erase(s.begin());
		for(int i = 0; i < ar[cur].size(); i++){
			int viz = ar[cur][i];
			if(marc[viz]) continue;
			s.erase(make_pair(dist[viz], viz));
			dist[viz] = min(dist[viz], dist[cur] + wg[cur][i]);
			s.insert(make_pair(dist[viz], viz));
		}
	}
}

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:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for(int i = 0; i < X.size(); i++)
      |                 ~~^~~~~~~~~~
walk.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i = 0; i < L.size(); i++)
      |                 ~~^~~~~~~~~~
walk.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i = 0; i < line.size(); i++){
      |                 ~~^~~~~~~~~~~~~
walk.cpp:73:19: 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 < X.size(); i++){
      |                 ~~^~~~~~~~~~
walk.cpp: In function 'void dijkstra(int)':
walk.cpp:104:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |   for(int i = 0; i < ar[cur].size(); i++){
      |                  ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 183 ms 18332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 183 ms 18332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -