# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
418091 |
2021-06-05T05:46:07 Z |
cfalas |
Sky Walking (IOI19_walk) |
C++14 |
|
4000 ms |
438516 KB |
#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<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, inters[t.S.F]){
if(v==t.S.S) continue;
ii targ = {t.S.F, v};
if(abs(t.S.S - v)-t.F < dist[targ]){
dist[targ] = abs(t.S.S - v)-t.F;
q.push({-dist[targ], targ});
}
}
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 = LLONG_MAX;
FOA(v, inters[g]) ans = min(ans, dist[{g, v}]+v);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
4038 ms |
129064 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
15684 KB |
Output is correct |
2 |
Execution timed out |
4090 ms |
438516 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
15684 KB |
Output is correct |
2 |
Execution timed out |
4090 ms |
438516 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |