#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define _all(T) T.begin(),T.end()
#define ll long long
#define pii pair<int,int>
#define fs first
#define sc second
#define pll pair<ll,ll>
const int mxn = 2e5+10;
const ll inf = 1e18;
vector<pii> paths[mxn];
vector<int> all;
map<pii,int> mp;
ll dist[mxn];
int N;
namespace DIJKSTRA{
priority_queue<pll,vector<pll>,greater<pll>> pq;
bitset<mxn> vis;
void GO(){
vis.reset();
for(int i = 0;i<mp.size();i++){
pq.push(pll(dist[i],i));
}
while(!pq.empty()){
auto [d,now] = pq.top();
pq.pop();
if(vis[now])continue;
//cerr<<now<<":"<<d<<endl;
vis[now] = true;
for(auto [nxt,w]:paths[now]){
if(vis[nxt])continue;
assert(w>=0);
if(d+w<dist[nxt]){
dist[nxt] = d+w;
pq.push(pll(d+w,nxt));
}
}
}
return;
}
}
long long min_distance(std::vector<int32_t> x, std::vector<int32_t> H, std::vector<int32_t> l, std::vector<int32_t> r, std::vector<int32_t> y, int32_t st, int32_t ed) {
all.push_back(0);
N = x.size();
for(auto &i:H)all.push_back(i);
for(auto &i:y)all.push_back(i);
sort(_all(all));
all.resize(unique(_all(all))-all.begin());
for(int i = 0;i<N;i++){
for(int j = 0;j<all.size();j++)mp[pii(i,j)] = mp.size();
}
assert(mp.size()<mxn);
/*
for(auto &i:mp){
cerr<<i.fs.fs<<','<<all[i.fs.sc]<<":"<<i.sc<<endl;
}
*/
for(int i = 0;i<N;i++){
for(int j = 0;j<all.size();j++){
for(int k = j+1;k<all.size();k++){
if(H[i]<all[k])break;
int a = mp[pii(i,j)],b = mp[pii(i,k)];
paths[a].push_back(pii(b,abs(all[j]-all[k])));
paths[b].push_back(pii(a,abs(all[j]-all[k])));
}
}
}
for(int i = 0;i<l.size();i++){
int s = l[i],e = r[i],h = y[i];
h = lower_bound(_all(all),h)-all.begin();
assert(all[h] == y[i]);
pii pre = pii(s,h);
for(int j = s+1;j<=e;j++){
if(H[j]<all[h])continue;
pii now = pii(j,h);
int a = mp[pre],b = mp[now];
assert(x[now.fs]>=x[pre.fs]);
paths[a].push_back(pii(b,x[now.fs]-x[pre.fs]));
paths[b].push_back(pii(a,x[now.fs]-x[pre.fs]));
pre = now;
}
}
fill(dist,dist+mxn,inf);
dist[mp[pii(st,0)]] = 0;
//cerr<<mp[pii(st,0)]<<','<<mp[pii(ed,0)]<<endl;
DIJKSTRA::GO();
ll ans = dist[mp[pii(ed,0)]];
if(ans>=inf)return -1;
else return ans;
}
Compilation message
walk.cpp: In function 'void DIJKSTRA::GO()':
walk.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<std::pair<int, int>, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0;i<mp.size();i++){
| ~^~~~~~~~~~
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int32_t, int32_t)':
walk.cpp:55:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int j = 0;j<all.size();j++)mp[pii(i,j)] = mp.size();
| ~^~~~~~~~~~~
walk.cpp:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int j = 0;j<all.size();j++){
| ~^~~~~~~~~~~
walk.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int k = j+1;k<all.size();k++){
| ~^~~~~~~~~~~
walk.cpp:76:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i = 0;i<l.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
3 ms |
6748 KB |
Output is correct |
4 |
Correct |
3 ms |
7004 KB |
Output is correct |
5 |
Correct |
18 ms |
10328 KB |
Output is correct |
6 |
Correct |
4 ms |
7000 KB |
Output is correct |
7 |
Correct |
8 ms |
8792 KB |
Output is correct |
8 |
Correct |
3 ms |
7004 KB |
Output is correct |
9 |
Correct |
3 ms |
6868 KB |
Output is correct |
10 |
Correct |
23 ms |
10328 KB |
Output is correct |
11 |
Correct |
6 ms |
7768 KB |
Output is correct |
12 |
Correct |
5 ms |
7516 KB |
Output is correct |
13 |
Correct |
9 ms |
7772 KB |
Output is correct |
14 |
Correct |
6 ms |
7516 KB |
Output is correct |
15 |
Correct |
4 ms |
7000 KB |
Output is correct |
16 |
Correct |
15 ms |
10076 KB |
Output is correct |
17 |
Correct |
18 ms |
10200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Execution timed out |
4067 ms |
1019244 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
20264 KB |
Output is correct |
2 |
Runtime error |
3912 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
20264 KB |
Output is correct |
2 |
Runtime error |
3912 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
3 ms |
6748 KB |
Output is correct |
4 |
Correct |
3 ms |
7004 KB |
Output is correct |
5 |
Correct |
18 ms |
10328 KB |
Output is correct |
6 |
Correct |
4 ms |
7000 KB |
Output is correct |
7 |
Correct |
8 ms |
8792 KB |
Output is correct |
8 |
Correct |
3 ms |
7004 KB |
Output is correct |
9 |
Correct |
3 ms |
6868 KB |
Output is correct |
10 |
Correct |
23 ms |
10328 KB |
Output is correct |
11 |
Correct |
6 ms |
7768 KB |
Output is correct |
12 |
Correct |
5 ms |
7516 KB |
Output is correct |
13 |
Correct |
9 ms |
7772 KB |
Output is correct |
14 |
Correct |
6 ms |
7516 KB |
Output is correct |
15 |
Correct |
4 ms |
7000 KB |
Output is correct |
16 |
Correct |
15 ms |
10076 KB |
Output is correct |
17 |
Correct |
18 ms |
10200 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Execution timed out |
4067 ms |
1019244 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |