#include "walk.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+5;
int N,M;
map<int,ll> mapa;
vector<int> poc[maxn],kraj[maxn];
ll getdist(int y,int h){
auto it=mapa.upper_bound(y-1);
if(it!=mapa.begin())
it--;
ll ans=1e18;
int br=5;
for(it;it!=mapa.end();it++){
br--;
if(br==0)
break;
if((it->first)>h)
break;
ans=min(ans,(it->second)+abs(y-(it->first)));
}
if(ans==1e18)
return -1;
return ans;
}
ll 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) {
N=x.size();
M=l.size();
for(int i=0;i<M;i++){
poc[l[i]].push_back(y[i]);
kraj[r[i]].push_back(y[i]);
}
for(int x:poc[0])
mapa[x]=x;
for(int i=1;i<N-1;i++){
if(mapa.size()==0)
return -1;
vector<pair<int,ll>> V;
for(int y:poc[i]){
ll d=getdist(y,h[i]);
if(d==-1)
break;
V.push_back({y,d});
}
for(int x:kraj[i])
mapa.erase(x);
for(auto x:V)
mapa[x.first]=x.second;
}
if(mapa.size()==0)
return -1;
ll res=9e18;
for(auto it=mapa.begin();it!=mapa.end();it++)
res=min(res,(it->first)+(it->second));
return res+x.back()-x[0];
}
Compilation message
walk.cpp: In function 'long long int getdist(int, int)':
walk.cpp:15:8: warning: statement has no effect [-Wunused-value]
15 | for(it;it!=mapa.end();it++){
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
7260 KB |
Output is correct |
2 |
Correct |
65 ms |
8796 KB |
Output is correct |
3 |
Correct |
77 ms |
11752 KB |
Output is correct |
4 |
Correct |
93 ms |
17236 KB |
Output is correct |
5 |
Correct |
118 ms |
21564 KB |
Output is correct |
6 |
Correct |
120 ms |
19520 KB |
Output is correct |
7 |
Correct |
52 ms |
13652 KB |
Output is correct |
8 |
Correct |
60 ms |
19204 KB |
Output is correct |
9 |
Correct |
107 ms |
20940 KB |
Output is correct |
10 |
Correct |
66 ms |
19528 KB |
Output is correct |
11 |
Correct |
9 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
7260 KB |
Output is correct |
2 |
Correct |
65 ms |
8796 KB |
Output is correct |
3 |
Correct |
77 ms |
11752 KB |
Output is correct |
4 |
Correct |
93 ms |
17236 KB |
Output is correct |
5 |
Correct |
118 ms |
21564 KB |
Output is correct |
6 |
Correct |
120 ms |
19520 KB |
Output is correct |
7 |
Correct |
52 ms |
13652 KB |
Output is correct |
8 |
Correct |
60 ms |
19204 KB |
Output is correct |
9 |
Correct |
107 ms |
20940 KB |
Output is correct |
10 |
Correct |
66 ms |
19528 KB |
Output is correct |
11 |
Correct |
9 ms |
6492 KB |
Output is correct |
12 |
Correct |
75 ms |
11360 KB |
Output is correct |
13 |
Correct |
50 ms |
16784 KB |
Output is correct |
14 |
Correct |
121 ms |
21492 KB |
Output is correct |
15 |
Correct |
77 ms |
17164 KB |
Output is correct |
16 |
Correct |
80 ms |
17196 KB |
Output is correct |
17 |
Correct |
78 ms |
17240 KB |
Output is correct |
18 |
Correct |
80 ms |
17072 KB |
Output is correct |
19 |
Correct |
79 ms |
17232 KB |
Output is correct |
20 |
Correct |
55 ms |
13648 KB |
Output is correct |
21 |
Correct |
18 ms |
8708 KB |
Output is correct |
22 |
Correct |
44 ms |
14864 KB |
Output is correct |
23 |
Correct |
59 ms |
15120 KB |
Output is correct |
24 |
Correct |
47 ms |
15492 KB |
Output is correct |
25 |
Correct |
44 ms |
15188 KB |
Output is correct |
26 |
Correct |
54 ms |
16208 KB |
Output is correct |
27 |
Correct |
120 ms |
21128 KB |
Output is correct |
28 |
Correct |
50 ms |
16720 KB |
Output is correct |
29 |
Correct |
122 ms |
19792 KB |
Output is correct |
30 |
Correct |
49 ms |
13648 KB |
Output is correct |
31 |
Correct |
108 ms |
20900 KB |
Output is correct |
32 |
Correct |
60 ms |
17728 KB |
Output is correct |
33 |
Incorrect |
74 ms |
18952 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |