Submission #418088

#TimeUsernameProblemLanguageResultExecution timeMemory
418088cfalasSky Walking (IOI19_walk)C++14
0 / 100
4090 ms462084 KiB
#include "walk.h" #include<bits/stdc++.h> using namespace std; #define mp make_pair #define INF 10000000 #define MOD 1000000007 #define MID ((l+r)/2) #define HASHMOD 2305843009213693951 #define ll long long #define ull unsigned long long #define F first #define S second typedef pair<ll, ll> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef map<int, int> mii; #define EPS 1e-6 #define FOR(i,n) for(int i=0;i<((int)(n));i++) #define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++) #define FOA(v, a) for(auto v : a) #define len(x) ((int) x.size()) long long min_distance(vector<int> x, vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) { vector<vii> adj(len(x)+1); set<pair<int, ii> > events; map<ii, long long> dist; set<ii> vert; FOR(i, len(x)){ events.insert({h[i], {1, i}}); vert.insert({x[i], i}); } FOR(i, len(y)){ events.insert({y[i], {0, i}}); } vector<set<int> > inters; inters.resize(len(x)); FOA(v, events){ #ifdef LOCAL cout<<v.F<<" "<<v.S.F<<" "<<v.S.S<<endl; #endif if(v.S.F==1){ vert.erase({x[v.S.S], v.S.S}); } else{ ii b = {x[l[v.S.S]], x[r[v.S.S]]}; auto it = vert.lower_bound({b.F, 0}); auto ne = it++; #ifdef LOCAL cout<<b.F<<" "<<b.S<<endl; #endif while(it!=vert.end() && ne!=vert.end() && it->F<=b.S){ adj[it->S].push_back({ne->S, v.F}); adj[ne->S].push_back({it->S, v.F}); inters[it->S].insert(v.F); inters[ne->S].insert(v.F); ne++, it++; } } } #ifdef LOCAL FOR(i, len(x)){ cout<<i<<": "; FOA(v, adj[i]) cout<<"("<<v.F<<" "<<v.S<<") "; cout<<endl; } #endif FOR(i, len(x)){ FOA(v, inters[i]) dist[{i, v}] = LLONG_MAX; } priority_queue<pair<ll, ii> > q; q.push({0, {s, 0}}); dist[{s, 0}] = 0; while(!q.empty()){ pair<int, ii> t = q.top(); q.pop(); if(-t.F > dist[t.S]) continue; #ifdef LOCAL cout<<t.S.F<<" "<<t.S.S<<": "<<t.F<<endl; #endif FOA(v, inters[t.S.F]){ if(v==t.S.S) continue; if(abs(t.S.S - v)-t.F < dist[{t.S.F, v}]){ dist[{t.S.F, v}] = abs(t.S.S - v)-t.F; q.push({-dist[{t.S.F, v}], {t.S.F, v}}); } } FOA(v, adj[t.S.F]){ if(abs(t.S.S - v.S)-t.F + abs(x[v.F]-x[t.S.F]) < dist[v]){ dist[v] = abs(t.S.S - v.S)-t.F + abs(x[v.F]-x[t.S.F]); q.push({-dist[v], v}); } } } ll ans = LLONG_MAX; FOA(v, inters[g]) ans = min(ans, dist[{g, v}]+v); return ans; }
#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...