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>
using namespace std;
typedef int ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
#define po pop_back
#define pb push_back
#define mk make_pair
#define lw lower_bound
#define up upper_bound
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 1e18
#define MIN -1e18
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define per(i,a,b) for(ll i=b;i>=a;i--)
#define con continue
#define freopen freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628
// typedef tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// template< typename T>
// using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,m,ans,mid,mn,mx,T,sum,h1,h2,e[1234567],b[1234567],c[1234567],d[1<<20],k,i,j,l,r,h,a[1234567],w,x,y,z;
bool used[1234567];
vector<int> v[1234567],vec,vv1,vv2;
string s1,s;
ll sz[1234567],par[1234567],tr[3234567],dist[123][123];
ll dx[4]={-1,1,0,0},dy[4]={0,0,-1,1},c1[123][123];
vector<array<ll, 3>> adj[123][123];
ll search(ll id, ll val){
return lw(v[id].begin(), v[id].end(), val) - v[id].begin();
}
ll djikstra(ll x1, ll x2, ll y1, ll y2){
for(ll i = 0; i < 60; i++)
for(ll j = 0; j < 60; j++)
dist[i][j] = MAX;
priority_queue<array<ll, 3>> pq;
dist[x1][x2] = 0;
pq.push({0, x1, x2});
while(!pq.empty()){
array<ll, 3> arr = pq.top();
pq.pop();
ll u1 = arr[1], u2 = arr[2];
if(arr[0] != dist[u1][u2])
continue;
if(u1 == x1 && u2 == x2)
break;
for(auto edge : adj[u1][u2]){
ll P = edge[0], Q = edge[1];
if(dist[P][Q] > dist[u1][u2] + edge[2]){
dist[P][Q] = dist[u1][u2] + edge[2];
pq.push({dist[P][Q], P, Q});
}
}
}
return dist[y1][y2];
}
ll min_distance(vl X, vl H,vl L,vl R,vl Y,ll s,ll g){
n = X.size();
m = Y.size();
for(ll i = 0; i < m; i++){
for(ll j = L[i]; j <= R[i]; j++){
if(H[j] >= Y[i])
v[j].pb(Y[i]);
}
}
for(ll i = 0; i < n; i++){
v[i].pb(0);
v[i].pb(H[i]);
sort(v[i].begin(),v[i].end());
}
for(ll i = 0; i < n; i++){
vl vec;
set<ll> st;
for(auto u:v[i])st.insert(u);
for(auto u:st)vec.pb(u);
v[i] = vec;
}
for(ll i = 0; i < n; i++){
for(ll j = 0; j < v[i].size() - 1; j++){
adj[i][j].pb({i, j + 1, v[i][j + 1] - v[i][j]});
adj[i][j + 1].pb({i, j, v[i][j + 1] - v[i][j]});
}
}
for(ll i = 0; i < m; i++){
ll tmp = -1;
for(ll j = L[i]; j <= R[i]; j++){
if(H[j] >= Y[i]){
if(tmp == -1){
tmp = j;
continue;
}
ll j1 = search(j, Y[i]) , tmp1 = search(tmp, Y[i]);
adj[j][j1].pb({tmp, tmp1, X[j] - X[tmp]});
adj[tmp][tmp1].pb({j, j1, X[j] - X[tmp]});
tmp = j;
}
}
}
ll res = djikstra(s,0,g,0);
if(res==MAX)return -1;
else return res;
}
Compilation message (stderr)
walk.cpp: In function 'll djikstra(ll, ll, ll, ll)':
walk.cpp:15:13: warning: overflow in implicit constant conversion [-Woverflow]
#define MAX 1e18
^
walk.cpp:38:26: note: in expansion of macro 'MAX'
dist[i][j] = MAX;
^~~
walk.cpp: In function 'll min_distance(vl, vl, vl, vl, vl, ll, ll)':
walk.cpp:82:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll j = 0; j < v[i].size() - 1; j++){
~~^~~~~~~~~~~~~~~~~
# | 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... |