#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef pair<int,int>pii;
const ll MAXN = 1e4+5;
const ll INF = 1e15+7;
vector<vector<int>>has(100);
//has[i] e lista de alturas em que i e intersetado
map<pii,vector<pair<pii,int>> >adj;
//mapi[{i,j}] e vector de pares adjacente,dist
map<pii,int>dist;
//map<pii,bool>visited;
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 i,j,prev,n=x.size(),m=l.size();
for(j=0;j<m;j++){
for(i=l[j];i<=r[j];i++){
if(h[i]>=y[j]){
has[i].pb(y[j]);
}
}
}
for(i=0;i<n;i++){
has[i].pb(0);
sort(has[i].begin(),has[i].end());
}
for(i=0;i<n;i++){
for(j=1;j<(int)has[i].size();j++){
adj[{i,has[i][j]}].pb({ {i,has[i][j-1]} ,has[i][j]-has[i][j-1]});
adj[{i,has[i][j-1]}].pb({ {i,has[i][j]} ,has[i][j]-has[i][j-1]});
}
}
for(j=0;j<m;j++){
prev=l[j];
for(i=l[j]+1;i<=r[j];i++){
if(h[i]<y[j])continue;
adj[{prev,y[j]}].pb({ {i,y[j]} , x[i]-x[prev]});
adj[{i,y[j]}].pb({ {prev,y[j]} , x[i]-x[prev]});
prev=i;
}
}
//dijkstra
priority_queue< pair<pii,int> >p;
for(i=0;i<n;i++){
for(j=0;j<(int)has[i].size();j++){
dist[{i,has[i][j]}]=INF;
// visited[{i,has[i][j]}]=false;
}
}
p.push({{s,0},0});
dist[{s,0}]=0;
pii cur,a;
while(!p.empty()){
cur=p.top().first;
p.pop();
for(auto u:adj[cur]){
if(dist[u.first]>dist[cur]+u.second){
dist[u.first]=dist[cur]+u.second;
p.push({u.first,-dist[u.first]});
}
}
}
if(dist[{g,0}]!=INF){
return dist[{g,0}];
}else{
return -1;
}
}
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:59:22: warning: overflow in conversion from 'long long int' to 'std::map<std::pair<int, int>, int>::mapped_type' {aka 'int'} changes value from '1000000000000007' to '-1530494969' [-Woverflow]
59 | dist[{i,has[i][j]}]=INF;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
Runtime error |
16 ms |
3000 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
16 ms |
3000 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |