Submission #254138

#TimeUsernameProblemLanguageResultExecution timeMemory
254138khangalSky Walking (IOI19_walk)C++14
0 / 100
129 ms114424 KiB
#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 == y1 && u2 == y2) 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]; } long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g){ n = x.size(); m = y.size(); sort(x.begin(),x.end()); for(int i = 0; i < m; ++i){ for(int j = l[i]; j <= r[i]; ++j){ if(h[j] >= y[i]) v[j].push_back(y[i]); } } for(int i = 0; i < n; ++i){ v[i].push_back(0); v[i].push_back(h[i]); } for(int i = 0; i < n; ++i) sort(v[i].begin(), v[i].end()); for(int i = 0; i < n; ++i){ vector<int> vec; for(int j = 0; j < (int)v[i].size() - 1; ++j){ if(v[i][j] != v[i][j + 1]) vec.push_back(v[i][j]); } if(!v[i].empty()) vec.push_back(v[i].back()); v[i] = vec; } for(int i = 0; i < n; ++i){ for(int j = 0; j < (int)v[i].size() - 1; ++j){ adj[i][j].push_back({i, j + 1, v[i][j + 1] - v[i][j]}); adj[i][j + 1].push_back({i, j, v[i][j + 1] - v[i][j]}); } } for(int i = 0; i < m; ++i){ int tmp = -1; for(int j = l[i]; j <= r[i]; ++j){ if(h[j] >= y[i]){ if(tmp == -1){ tmp = j; continue; } int jj = search(j, y[i]), tmpp = search(tmp, y[i]); adj[j][jj].push_back({tmp, tmpp, x[j] - x[tmp]}); adj[tmp][tmpp].push_back({j, jj, 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;
                          ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...