#include <bits/stdc++.h>
#include "walk.h"
using namespace std;
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000000000000
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
struct greateri
{
template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};
ll so,go;
ll n,m;
vector<pair<ll,pair<ll,ll>>>graph[100001];
map<ll,pair<ll,ll>>gg;
map<pair<ll,ll>,ll>dist;
map<pair<ll,ll>,ll>in_queu;
ll min_distance(vector<int>x,vector<int>h,vector<int>l,vector<int>r,vector<int>y,int s,int g)
{
for (ll i = 0; i < x.size(); ++i)
{
gg[x[i]]={h[i],i};
}
for (ll i = 0; i < l.size(); ++i)
{
auto k = gg.lower_bound(x[l[i]]);
auto hedi = (*k).first;
auto yo = (*k).second;
vector<pair<ll,ll>>connect;
while(hedi<=x[r[i]] && k!=gg.end())
{
if(yo.first>=y[i])
{
connect.pb({hedi,yo.second});
}
k++;
hedi = (*k).first;
yo = (*k).second;
}
for (ll j = 0; j < connect.size(); ++j)
{
for (ll d = j+1; d < connect.size(); ++d)
{
ll node = connect[j].second;
ll node1 = connect[d].second;
ll weight = abs(connect[d].first-connect[j].first);
graph[node].pb({node1,{y[i],weight}});
graph[node1].pb({node,{y[i],weight}});
}
}
}
queue<pair<ll,ll>>now;
now.push({s,0});
dist[{s,0}]=0;
ll ans=-1;
while(!now.empty())
{
auto ni = now.front();
//debug(ni.first);
now.pop();
in_queu[ni]=0;
for (ll i = 0; i < graph[ni.first].size(); ++i)
{
ll to = graph[ni.first][i].first;
ll index = graph[ni.first][i].second.first;
if((dist.find({to,index})==dist.end()||(dist[{to,index}]>dist[ni]+abs(ni.second-index)+abs(x[ni.first]-x[to]))))
{
//debug(to);
dist[{to,index}]=dist[ni]+abs(ni.second-index)+abs(x[ni.first]-x[to]);
if(to==g)
{
if(ans==-1)ans=dist[{to,index}]+index;
else ans=min(ans,dist[{to,index}]+index);}
if(in_queu.find({to,index})==in_queu.end()||!in_queu[{to,index}])
{in_queu[{to,index}]=1,now.push({to,index});}
}
}
}
return ans;
}
//code the AC sol !
// BS/queue/map
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:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < x.size(); ++i)
~~^~~~~~~~~~
walk.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < l.size(); ++i)
~~^~~~~~~~~~
walk.cpp:48:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll j = 0; j < connect.size(); ++j)
~~^~~~~~~~~~~~~~~~
walk.cpp:50:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll d = j+1; d < connect.size(); ++d)
~~^~~~~~~~~~~~~~~~
walk.cpp:70:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < graph[ni.first].size(); ++i)
~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2684 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
36 ms |
3192 KB |
Output is correct |
6 |
Correct |
29 ms |
3192 KB |
Output is correct |
7 |
Correct |
25 ms |
3192 KB |
Output is correct |
8 |
Correct |
20 ms |
3192 KB |
Output is correct |
9 |
Correct |
7 ms |
2680 KB |
Output is correct |
10 |
Correct |
71 ms |
3448 KB |
Output is correct |
11 |
Correct |
5 ms |
2680 KB |
Output is correct |
12 |
Correct |
5 ms |
2744 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
5 ms |
2680 KB |
Output is correct |
16 |
Correct |
5 ms |
2680 KB |
Output is correct |
17 |
Correct |
61 ms |
3320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Execution timed out |
4086 ms |
162608 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
311 ms |
17464 KB |
Output is correct |
2 |
Runtime error |
3114 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
311 ms |
17464 KB |
Output is correct |
2 |
Runtime error |
3114 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2684 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
36 ms |
3192 KB |
Output is correct |
6 |
Correct |
29 ms |
3192 KB |
Output is correct |
7 |
Correct |
25 ms |
3192 KB |
Output is correct |
8 |
Correct |
20 ms |
3192 KB |
Output is correct |
9 |
Correct |
7 ms |
2680 KB |
Output is correct |
10 |
Correct |
71 ms |
3448 KB |
Output is correct |
11 |
Correct |
5 ms |
2680 KB |
Output is correct |
12 |
Correct |
5 ms |
2744 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
5 ms |
2680 KB |
Output is correct |
16 |
Correct |
5 ms |
2680 KB |
Output is correct |
17 |
Correct |
61 ms |
3320 KB |
Output is correct |
18 |
Correct |
4 ms |
2680 KB |
Output is correct |
19 |
Correct |
5 ms |
2680 KB |
Output is correct |
20 |
Execution timed out |
4086 ms |
162608 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |