Submission #418296

#TimeUsernameProblemLanguageResultExecution timeMemory
418296cfalasSky Walking (IOI19_walk)C++14
10 / 100
4075 ms398224 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, ll> 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}] = HASHMOD; } priority_queue<pair<ll, ii> > q; q.push({0, {s, 0}}); dist[{s, 0}] = 0; while(!q.empty()){ pair<ll, 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, adj[t.S.F]){ ll new_d = abs(t.S.S - v.S)-t.F + abs(x[v.F]-x[t.S.F]); if(new_d < dist[v]){ dist[v] = new_d; q.push({-dist[v], v}); } } } ll ans = HASHMOD-1; FOA(v, inters[g]) ans = min(ans, dist[{g, v}]+v); if(ans==HASHMOD-1) return -1; 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...