Submission #296426

#TimeUsernameProblemLanguageResultExecution timeMemory
296426theStaticMindSky Walking (IOI19_walk)C++14
10 / 100
4098 ms119048 KiB
#include <bits/stdc++.h>
#include "walk.h"
using namespace std;
#define ii pair<int,int>

bool operator<(ii& a, ii& b){
	return a.first < b.first || (a.first == b.first && a.second < b.second);
}

vector<int>E[100000], B[100000];
vector<ii> adj[100000];
unordered_map<int, long long> val[100000];
unordered_set<int> vis[100000];

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) {
	map<int, int> curr;
	priority_queue<pair<long long, ii>> Q;

	for(int i = 0; i < r.size(); i++){
		E[r[i]].push_back(y[i]);
		B[l[i]].push_back(y[i]);
	}

	for(int i = 0; i < x.size(); i++){

		for(auto& Y : curr){
			if(Y.first > h[i]) break;

			adj[i].push_back({Y.second, Y.first});
			adj[Y.second].push_back({i, Y.first});

			Y.second = i;
		}

		for(auto Y : E[i]) curr.erase(Y);
		for(auto Y : B[i]) curr[Y] = i;
	}

	val[s][0] = 0;
	Q.push({0, {s, 0}});

	while(!Q.empty()){
		ii p = Q.top().second;
		Q.pop();
		if(vis[p.first].count(p.second)) continue;
		vis[p.first].insert(p.second);
		for(auto y : adj[p.first]){
			if(vis[y.first].count(y.second) || (val[y.first].count(y.second) && val[y.first][y.second] <= val[p.first][p.second] + abs(p.second - y.second) + abs(x[p.first] - x[y.first]))) continue;
			val[y.first][y.second] = val[p.first][p.second] + abs(p.second - y.second) + abs(x[p.first] - x[y.first]);
			Q.push({-val[y.first][y.second], y});
		}
	}
	long long ans = 1e18;
	for(auto p : val[g]){
		ans = min(ans, p.first + p.second);
	}
	if(ans == 1e18) return -1;
	return ans;
}

Compilation message (stderr)

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:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for(int i = 0; i < r.size(); i++){
      |                 ~~^~~~~~~~~~
walk.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int i = 0; i < x.size(); i++){
      |                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...