# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
932301 |
2024-02-23T07:36:38 Z |
hmm789 |
Sky Walking (IOI19_walk) |
C++14 |
|
4000 ms |
866396 KB |
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000000000000000
#define MOD 998244353
const int B = 316;
bool cmp(pair<pair<int, int>, pair<int, int>> a, pair<pair<int, int>, pair<int, int>> b) {
if(a.second.first/B != b.second.first/B) return a.second.first/B < b.second.first/B;
else return a.second.second < b.second.second;
}
#undef int
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int a, int b) {
#define int long long
int n = x.size(), m = l.size(), idx, x1, y1, ht;
pair<pair<int, int>, pair<int, int>> qry[m];
for(int i = 0; i < m; i++) qry[i] = {{y[i], i}, {l[i], r[i]}};
sort(qry, qry+m, cmp);
int L = 0, R = -1;
set<pair<int, int>> s;
vector<int> inters[m];
for(int i = 0; i < m; i++) {
ht = qry[i].first.first; idx = qry[i].first.second; x1 = qry[i].second.first; y1 = qry[i].second.second;
while(L > x1) {
L--;
s.insert({h[L], L});
}
while(R < y1) {
R++;
s.insert({h[R], R});
}
while(L < x1) {
s.erase(s.find({h[L], L}));
L++;
}
while(R > y1) {
s.erase(s.find({h[R], R}));
R--;
}
for(auto it = s.rbegin(); it != s.rend(); it++) {
if(it->first < ht) break;
inters[idx].push_back(it->second);
}
}
map<pair<int, int>, int> mp;
set<int> tower[n];
for(int i = 0; i < n; i++) tower[i].insert(0);
for(int i = 0; i < m; i++) {
sort(inters[i].begin(), inters[i].end());
for(int j : inters[i]) {
tower[j].insert(y[i]);
}
}
idx = 0;
vector<pair<int, int>> back;
for(int i = 0; i < n; i++) {
for(int j : tower[i]) {
back.push_back({x[i], j});
mp[{x[i], j}] = idx++;
}
}
vector<int> adj[idx];
for(int i = 0; i < n; i++) {
int prv = -1;
for(int j : tower[i]) {
if(prv != -1) {
adj[mp[{x[i], j}]].push_back(mp[{x[i], prv}]);
adj[mp[{x[i], prv}]].push_back(mp[{x[i], j}]);
}
prv = j;
}
}
for(int i = 0; i < m; i++) {
int prv = -1;
for(int j : inters[i]) {
if(prv != -1) {
adj[mp[{x[j], y[i]}]].push_back(mp[{x[prv], y[i]}]);
adj[mp[{x[prv], y[i]}]].push_back(mp[{x[j], y[i]}]);
}
prv = j;
}
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
int dist[idx];
memset(dist, -1, sizeof(dist));
dist[mp[{x[a], 0}]] = 0;
pq.push({0, mp[{x[a], 0}]});
while(!pq.empty()) {
pair<int, int> c = pq.top();
pq.pop();
if(dist[c.second] != c.first) continue;
for(int i : adj[c.second]) {
int nd = abs(back[i].first-back[c.second].first) + abs(back[i].second-back[c.second].second) + c.first;
if(dist[i] == -1 || dist[i] > nd) {
dist[i] = nd;
pq.push({nd, i});
}
}
}
return dist[mp[{x[b], 0}]];
#undef int
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2099 ms |
170880 KB |
Output is correct |
4 |
Correct |
1844 ms |
193324 KB |
Output is correct |
5 |
Correct |
1415 ms |
169032 KB |
Output is correct |
6 |
Correct |
1231 ms |
151916 KB |
Output is correct |
7 |
Correct |
1366 ms |
169020 KB |
Output is correct |
8 |
Correct |
2957 ms |
217420 KB |
Output is correct |
9 |
Correct |
1532 ms |
165796 KB |
Output is correct |
10 |
Correct |
2796 ms |
263596 KB |
Output is correct |
11 |
Correct |
911 ms |
100028 KB |
Output is correct |
12 |
Correct |
548 ms |
82348 KB |
Output is correct |
13 |
Correct |
2194 ms |
231300 KB |
Output is correct |
14 |
Correct |
582 ms |
77344 KB |
Output is correct |
15 |
Correct |
1121 ms |
81336 KB |
Output is correct |
16 |
Correct |
613 ms |
81640 KB |
Output is correct |
17 |
Correct |
1029 ms |
78188 KB |
Output is correct |
18 |
Correct |
557 ms |
88948 KB |
Output is correct |
19 |
Correct |
13 ms |
4308 KB |
Output is correct |
20 |
Correct |
164 ms |
40872 KB |
Output is correct |
21 |
Correct |
493 ms |
74196 KB |
Output is correct |
22 |
Correct |
523 ms |
81760 KB |
Output is correct |
23 |
Correct |
3609 ms |
95292 KB |
Output is correct |
24 |
Correct |
507 ms |
79728 KB |
Output is correct |
25 |
Correct |
506 ms |
77132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
21732 KB |
Output is correct |
2 |
Execution timed out |
4075 ms |
866396 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
21732 KB |
Output is correct |
2 |
Execution timed out |
4075 ms |
866396 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
2099 ms |
170880 KB |
Output is correct |
21 |
Correct |
1844 ms |
193324 KB |
Output is correct |
22 |
Correct |
1415 ms |
169032 KB |
Output is correct |
23 |
Correct |
1231 ms |
151916 KB |
Output is correct |
24 |
Correct |
1366 ms |
169020 KB |
Output is correct |
25 |
Correct |
2957 ms |
217420 KB |
Output is correct |
26 |
Correct |
1532 ms |
165796 KB |
Output is correct |
27 |
Correct |
2796 ms |
263596 KB |
Output is correct |
28 |
Correct |
911 ms |
100028 KB |
Output is correct |
29 |
Correct |
548 ms |
82348 KB |
Output is correct |
30 |
Correct |
2194 ms |
231300 KB |
Output is correct |
31 |
Correct |
582 ms |
77344 KB |
Output is correct |
32 |
Correct |
1121 ms |
81336 KB |
Output is correct |
33 |
Correct |
613 ms |
81640 KB |
Output is correct |
34 |
Correct |
1029 ms |
78188 KB |
Output is correct |
35 |
Correct |
557 ms |
88948 KB |
Output is correct |
36 |
Correct |
13 ms |
4308 KB |
Output is correct |
37 |
Correct |
164 ms |
40872 KB |
Output is correct |
38 |
Correct |
493 ms |
74196 KB |
Output is correct |
39 |
Correct |
523 ms |
81760 KB |
Output is correct |
40 |
Correct |
3609 ms |
95292 KB |
Output is correct |
41 |
Correct |
507 ms |
79728 KB |
Output is correct |
42 |
Correct |
506 ms |
77132 KB |
Output is correct |
43 |
Correct |
163 ms |
21732 KB |
Output is correct |
44 |
Execution timed out |
4075 ms |
866396 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |