# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
418296 |
2021-06-05T09:31:20 Z |
cfalas |
Sky Walking (IOI19_walk) |
C++14 |
|
4000 ms |
398224 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, 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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
288 KB |
Output is correct |
3 |
Correct |
1 ms |
276 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
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 |
4053 ms |
130740 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
203 ms |
16064 KB |
Output is correct |
2 |
Execution timed out |
4075 ms |
398224 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
203 ms |
16064 KB |
Output is correct |
2 |
Execution timed out |
4075 ms |
398224 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 |
288 KB |
Output is correct |
3 |
Correct |
1 ms |
276 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Execution timed out |
4053 ms |
130740 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |