# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
209785 |
2020-03-15T14:16:08 Z |
medk |
Sky Walking (IOI19_walk) |
C++14 |
|
4000 ms |
90304 KB |
#include "walk.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define x first
#define y second
using namespace std;
int n,m;
vector<vector<int>> twr,br;
vector<pair<ll,ll>> tower;
vector<pair<ll,pair<ll,ll>>> bridge;
map<pair<int,int>,ll> dist;
ll 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=l.size();
twr.resize(n), br.resize(m);
for(int i=0;i<n;i++) tower.pb({h[i],x[i]});
for(int i=0;i<m;i++) bridge.pb({y[i],{x[l[i]],x[r[i]]}});
pair<ll,ll> ps=tower[s], pg=tower[g];
sort(tower.begin(),tower.end()); reverse(tower.begin(),tower.end());
sort(bridge.begin(),bridge.end()); reverse(bridge.begin(),bridge.end());
for(int i=0;i<n;i++)
{
if(tower[i]==ps) s=i;
if(tower[i]==pg) g=i;
}
twr[g].pb(-1);
set<pair<int,int>> st;
int ptr=0;
for(int i=0;i<m;i++)
{
int H=bridge[i].x,L=bridge[i].y.x,R=bridge[i].y.y;
if(L>R) swap(L,R);
while(ptr<n)
{
if(tower[ptr].x<H) break;
st.insert({tower[ptr].y,ptr});
ptr++;
}
auto itL=st.lower_bound({L,-1}), itR=st.lower_bound({R+1,-1});
while(itL!=itR && itL!=st.end())
{
twr[(*itL).y].pb(i);
br[i].pb((*itL).y);
itL++;
}
}
set<pair<int,int>> vis;
dist[{s,-1}]=0;
priority_queue<pair<pair<ll,pair<int,int>>,bool>> dij;
dij.push({{0,{s,-1}},1});
while(!dij.empty())
{
ll d=-dij.top().x.x; int T=dij.top().x.y.x, B=dij.top().x.y.y; bool which=dij.top().y;
dij.pop();
if(vis.count({T,B})) continue;
vis.insert({T,B});
if(which) for(int v:twr[T])
{
if(v==B) continue;
if(vis.count({T,v})) continue;
ll newD=d+abs((v==-1?0:bridge[v].x)-(B==-1?0:bridge[B].x));
if(newD<(dist.count({T,v})?dist[{T,v}]:2e18))
{
dist[{T,v}]=newD;
dij.push({{-newD,{T,v}},which^1});
}
}
else if(B!=-1) for(int v:br[B])
{
if(v==T) continue;
if(vis.count({v,B})) continue;
ll newD=d+abs(tower[v].y-tower[T].y);
if(newD<(dist.count({v,B})?dist[{v,B}]:2e18))
{
dist[{v,B}]=newD;
dij.push({{-newD,{v,B}},which^1});
}
}
}
if(dist.count({g,-1})) return dist[{g,-1}];
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
7 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
7 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Execution timed out |
4096 ms |
58228 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
19824 KB |
Output is correct |
2 |
Execution timed out |
4026 ms |
90304 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
19824 KB |
Output is correct |
2 |
Execution timed out |
4026 ms |
90304 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
7 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
7 ms |
504 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
256 KB |
Output is correct |
20 |
Execution timed out |
4096 ms |
58228 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |