This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
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 < l.size(); ++i)
{
graph[l[i]].pb({r[i],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 (stderr)
walk.cpp: In function 'long long int solve(long long int, long long int)':
walk.cpp:34: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:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < l.size(); ++i)
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |