#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,ll>>graph[100001];
map<pair<ll,ll>,ll>dp;
vector<int>xo;
map<ll,pair<ll,ll>>gg;
ll solve(ll node,ll index)
{
ll ans=INF;
if(node==(n-1))
{
//debug(index);
return index;
}
if(dp.find({node,index})!=dp.end())return dp[{node,index}];
for (ll i = 0; i < graph[node].size(); ++i)
{
ll next = graph[node][i].first;
ll indexi = graph[node][i].second;
ans=min(ans,solve(next,indexi)+abs(xo[node]-xo[next])+abs(index-indexi));
}
return dp[{node,index}]=ans;
}
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]});
}
}
}
n=x.size();
xo=x;
ll ans=solve(0,0);
if(ans==INF)return -1;
return ans;
}
//code the AC sol !
// BS/queue/map
Compilation message
walk.cpp: In function 'long long int solve(long long int, long long int)':
walk.cpp:35:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < graph[node].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>, int, int)':
walk.cpp:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < x.size(); ++i)
~~^~~~~~~~~~
walk.cpp:49:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < l.size(); ++i)
~~^~~~~~~~~~
walk.cpp:65:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll j = 0; j < connect.size(); ++j)
~~^~~~~~~~~~~~~~~~
walk.cpp:67:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll d = j+1; d < connect.size(); ++d)
~~^~~~~~~~~~~~~~~~
walk.cpp:71:9: warning: unused variable 'weight' [-Wunused-variable]
ll weight = abs(connect[d].first-connect[j].first);
^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
145 ms |
10820 KB |
Output is correct |
2 |
Runtime error |
3655 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
145 ms |
10820 KB |
Output is correct |
2 |
Runtime error |
3655 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |