# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
147043 |
2019-08-27T10:08:03 Z |
gs14004 |
Sky Walking (IOI19_walk) |
C++17 |
|
4000 ms |
622872 KB |
#include "walk.h"
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
using lint = long long;
using pi = pair<lint, int>;
const int MAXN = 100005;
const int MAXV = 2000005;
struct intv{
int s, e, x;
bool operator<(const intv &i)const{
return x < i.x;
}
};
struct point{
int x, y, idx;
};
int n, m;
vector<int> witness[MAXN];
vector<pi> event[MAXN];
vector<pi> gph[MAXV];
lint dist[MAXV];
lint dijkstra(int s, int e){
priority_queue<pi, vector<pi>, greater<pi> > pq;
memset(dist, 0x3f, sizeof(dist));
dist[s] = 0;
pq.emplace(0, s);
while(!pq.empty()){
auto x = pq.top();
pq.pop();
if(dist[x.second] != x.first) continue;
for(auto &j : gph[x.second]){
if(dist[j.second] > x.first + j.first){
dist[j.second] = x.first + j.first;
pq.emplace(dist[j.second], j.second);
}
}
}
if(dist[e] > 1e17) return -1;
return dist[e];
}
void add_edge(point x, point y){
// printf("(%d, %d) <-> (%d, %d)\n", x.x, x.y, y.x, y.y);
int dist = abs(x.x - y.x) + abs(x.y - y.y);
gph[x.idx].emplace_back(dist, y.idx);
gph[y.idx].emplace_back(dist, x.idx);
}
void make_vertex(vector<intv> v){
for(auto &i : v){
event[i.s].emplace_back(i.x, +1);
event[i.e+1].emplace_back(i.x, -1);
}
multiset<int> swp;
for(int i=0; i<n; i++){
for(auto &j : event[i]){
if(j.second == +1) swp.insert(j.first);
else swp.erase(swp.find(j.first));
}
vector<int> nxt = witness[i];
for(auto &j : witness[i]){
if(j == 0) continue;
auto l = swp.upper_bound(j);
if(l != swp.end()) nxt.push_back(*l);
l = swp.lower_bound(j);
if(l != swp.begin()) nxt.push_back(*prev(l));
}
for(auto &j : swp) nxt.push_back(j);
sort(nxt.begin(), nxt.end());
nxt.resize(unique(nxt.begin(), nxt.end()) - nxt.begin());
witness[i] = nxt;
}
}
long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int e) {
n = sz(x);
m = sz(l);
for(int i=0; i<m; i++){
for(int j=0; j<n; j++) witness[j].push_back(y[i]);
witness[l[i]].push_back(y[i]);
witness[r[i]].push_back(y[i]);
}
witness[s].push_back(0);
witness[e].push_back(0);
vector<pi> points;
vector<intv> hors;
set<int> alive;
for(int i=0; i<n; i++){
points.emplace_back(h[i], i);
alive.insert(i);
}
for(int i=0; i<m; i++) hors.push_back({l[i], r[i], y[i]});
sort(points.begin(), points.end());
sort(hors.begin(), hors.end());
int ptr = 0;
for(auto &i : hors){
while(ptr < sz(points) && points[ptr].first < i.x){
alive.erase(points[ptr++].second);
}
if(i.s <= s && s <= i.e){
auto it = alive.lower_bound(s);
if(it != alive.end()) witness[*it].push_back(i.x);
if(it != alive.begin() && *it != s) witness[*prev(it)].push_back(i.x);
}
if(i.s <= e && e <= i.e){
auto it = alive.lower_bound(e);
if(it != alive.end()) witness[*it].push_back(i.x);
if(it != alive.begin() && *it != e) witness[*prev(it)].push_back(i.x);
}
}
make_vertex(hors);
vector<point> ans;
for(int i=0; i<n; i++){
for(auto &j : witness[i]){
int num = ans.size();
ans.push_back({x[i], j, num});
}
}
auto cmpx = [&](const point &x, const point &y) { return pi(x.x, x.y) < pi(y.x, y.y); };
auto cmpy = [&](const point &x, const point &y) { return pi(x.y, x.x) < pi(y.y, y.x); };
sort(ans.begin(), ans.end(), cmpx);
for(int i=0; i<n; i++){
int st = lower_bound(ans.begin(), ans.end(), (point){x[i], 0, -1}, cmpx) - ans.begin();
int ed = upper_bound(ans.begin(), ans.end(), (point){x[i], h[i], -1}, cmpx) - ans.begin();
for(int j=st+1; j<ed; j++){
add_edge(ans[j-1], ans[j]);
}
}
sort(ans.begin(), ans.end(), cmpy);
for(int i=0; i<m; i++){
int st = lower_bound(ans.begin(), ans.end(), (point){x[l[i]], y[i], -1}, cmpy) - ans.begin();
int ed = upper_bound(ans.begin(), ans.end(), (point){x[r[i]], y[i], -1}, cmpy) - ans.begin();
for(int j=st+1; j<ed; j++){
add_edge(ans[j-1], ans[j]);
}
}
s = lower_bound(ans.begin(), ans.end(), (point){x[s], 0, -1}, cmpy)->idx;
e = lower_bound(ans.begin(), ans.end(), (point){x[e], 0, -1}, cmpy)->idx;
return dijkstra(s, e);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
67704 KB |
Output is correct |
2 |
Correct |
70 ms |
67708 KB |
Output is correct |
3 |
Correct |
64 ms |
67704 KB |
Output is correct |
4 |
Correct |
65 ms |
67704 KB |
Output is correct |
5 |
Correct |
66 ms |
67748 KB |
Output is correct |
6 |
Correct |
65 ms |
67732 KB |
Output is correct |
7 |
Correct |
64 ms |
67816 KB |
Output is correct |
8 |
Correct |
65 ms |
67704 KB |
Output is correct |
9 |
Correct |
64 ms |
67692 KB |
Output is correct |
10 |
Correct |
66 ms |
67832 KB |
Output is correct |
11 |
Correct |
65 ms |
67808 KB |
Output is correct |
12 |
Correct |
80 ms |
67704 KB |
Output is correct |
13 |
Correct |
65 ms |
67704 KB |
Output is correct |
14 |
Correct |
65 ms |
67704 KB |
Output is correct |
15 |
Correct |
64 ms |
67704 KB |
Output is correct |
16 |
Correct |
64 ms |
67808 KB |
Output is correct |
17 |
Correct |
73 ms |
67848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
67564 KB |
Output is correct |
2 |
Correct |
76 ms |
67576 KB |
Output is correct |
3 |
Execution timed out |
4154 ms |
622872 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4133 ms |
619352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4133 ms |
619352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
67704 KB |
Output is correct |
2 |
Correct |
70 ms |
67708 KB |
Output is correct |
3 |
Correct |
64 ms |
67704 KB |
Output is correct |
4 |
Correct |
65 ms |
67704 KB |
Output is correct |
5 |
Correct |
66 ms |
67748 KB |
Output is correct |
6 |
Correct |
65 ms |
67732 KB |
Output is correct |
7 |
Correct |
64 ms |
67816 KB |
Output is correct |
8 |
Correct |
65 ms |
67704 KB |
Output is correct |
9 |
Correct |
64 ms |
67692 KB |
Output is correct |
10 |
Correct |
66 ms |
67832 KB |
Output is correct |
11 |
Correct |
65 ms |
67808 KB |
Output is correct |
12 |
Correct |
80 ms |
67704 KB |
Output is correct |
13 |
Correct |
65 ms |
67704 KB |
Output is correct |
14 |
Correct |
65 ms |
67704 KB |
Output is correct |
15 |
Correct |
64 ms |
67704 KB |
Output is correct |
16 |
Correct |
64 ms |
67808 KB |
Output is correct |
17 |
Correct |
73 ms |
67848 KB |
Output is correct |
18 |
Correct |
77 ms |
67564 KB |
Output is correct |
19 |
Correct |
76 ms |
67576 KB |
Output is correct |
20 |
Execution timed out |
4154 ms |
622872 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |