# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
977942 |
2024-05-08T14:17:44 Z |
opPO |
Sky Walking (IOI19_walk) |
C++14 |
|
2234 ms |
681700 KB |
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)x.size()
using pii = pair<int, int>;
const int N = 2e6 + 52;
const int OO = 1e18;
vector<pii> g[N];
vector<int> hs[N];
map<pii, int> mapka;
int unused;
int get_id(int i, int h) {
if (mapka.find(make_pair(i, h)) == mapka.end()) {
hs[i].push_back(h);
mapka[{i, h}] = unused++;
}
return mapka[{i, h}];
}
long long min_distance(std::vector<int32_t> x, std::vector<int32_t> h, std::vector<int32_t> l, std::vector<int32_t> r, std::vector<int32_t> y, int32_t S, int32_t F) {
int n = sz(x);
int m = sz(l);
for (int i = 0; i < n; i++) {
mapka[{i, 0}] = unused++;
hs[i].push_back(0);
}
vector<pii> heights;
for (int i = 0; i < n; i++) {
heights.push_back({h[i], i});
}
sort(heights.rbegin(), heights.rend());
vector<pair<int, pii>> skys;
for (int i = 0; i < m; i++) {
skys.push_back({y[i], {l[i], r[i]}});
}
sort(skys.rbegin(), skys.rend());
set<int> can;
int ptr = 0;
for (int i = 0; i < m; i++) {
int Y = skys[i].first;
int L = skys[i].second.first, R = skys[i].second.second;
while (ptr < n && heights[ptr].first >= Y) {
can.insert(heights[ptr].second);
ptr++;
}
auto it = can.lower_bound(L);
vector<int> ps;
while (it != can.end() && (*it) <= R) {
ps.push_back(*it);
++it;
}
assert(sz(ps) >= 2);
for (int i = 1; i < sz(ps); i++) {
int prv = get_id(ps[i - 1], Y), cur = get_id(ps[i], Y);
g[prv].push_back({cur, x[ps[i]] - x[ps[i - 1]]});
g[cur].push_back({prv, x[ps[i]] - x[ps[i - 1]]});
}
}
for (int i = 0; i < n; i++) {
sort(hs[i].begin(), hs[i].end());
hs[i].resize(unique(hs[i].begin(), hs[i].end()) - hs[i].begin());
for (int j = 0; j < sz(hs[i]) - 1; j++) {
int u = mapka[{i, hs[i][j]}], v = mapka[{i, hs[i][j + 1]}];
int w = hs[i][j + 1] - hs[i][j];
g[u].push_back({v, w});
g[v].push_back({u, w});
}
}
set<pii> setik;
setik.insert({0, mapka[{S, 0}]});
vector<int> dist(N, OO);
dist[mapka[{S, 0}]] = 0;
while (!setik.empty()) {
pii cur = *setik.begin(); setik.erase(setik.begin());
int dst = cur.first, v = cur.second;
if (dst > dist[v]) continue;
for (auto &to : g[v]) {
if (dst + to.second < dist[to.first]) {
dist[to.first] = dst + to.second;
setik.insert({dist[to.first], to.first});
}
}
}
return (dist[mapka[{F, 0}]] == OO ? -1 : dist[mapka[{F, 0}]]);
}
/*
7 7
0 8
3 7
5 9
7 7
10 6
12 6
14 9
0 1 1
0 2 6
0 6 8
2 3 1
2 6 7
3 4 2
4 6 5
1 5
*/
/*
5 3
0 6
4 6
5 6
6 6
9 6
3 4 1
1 3 3
0 2 6
0 4
*/
/*
g++ -std=gnu++14 -O2 -Wall -pipe -static -o "walk" "grader.cpp" "walk.cpp"
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
109904 KB |
Output is correct |
2 |
Correct |
25 ms |
109824 KB |
Output is correct |
3 |
Correct |
25 ms |
109904 KB |
Output is correct |
4 |
Correct |
26 ms |
109916 KB |
Output is correct |
5 |
Correct |
27 ms |
109908 KB |
Output is correct |
6 |
Correct |
26 ms |
110060 KB |
Output is correct |
7 |
Correct |
26 ms |
109904 KB |
Output is correct |
8 |
Correct |
25 ms |
109916 KB |
Output is correct |
9 |
Correct |
25 ms |
109916 KB |
Output is correct |
10 |
Correct |
25 ms |
110032 KB |
Output is correct |
11 |
Correct |
26 ms |
109940 KB |
Output is correct |
12 |
Correct |
26 ms |
110068 KB |
Output is correct |
13 |
Correct |
25 ms |
109916 KB |
Output is correct |
14 |
Correct |
25 ms |
109904 KB |
Output is correct |
15 |
Correct |
25 ms |
109992 KB |
Output is correct |
16 |
Correct |
27 ms |
109912 KB |
Output is correct |
17 |
Correct |
30 ms |
110164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
109916 KB |
Output is correct |
2 |
Correct |
26 ms |
110160 KB |
Output is correct |
3 |
Correct |
1479 ms |
241944 KB |
Output is correct |
4 |
Correct |
1485 ms |
258748 KB |
Output is correct |
5 |
Correct |
1016 ms |
239940 KB |
Output is correct |
6 |
Correct |
904 ms |
224624 KB |
Output is correct |
7 |
Correct |
996 ms |
239492 KB |
Output is correct |
8 |
Correct |
1871 ms |
282320 KB |
Output is correct |
9 |
Correct |
1173 ms |
239900 KB |
Output is correct |
10 |
Correct |
2094 ms |
321840 KB |
Output is correct |
11 |
Correct |
787 ms |
184800 KB |
Output is correct |
12 |
Correct |
490 ms |
168496 KB |
Output is correct |
13 |
Correct |
1783 ms |
295028 KB |
Output is correct |
14 |
Correct |
378 ms |
166212 KB |
Output is correct |
15 |
Correct |
337 ms |
168116 KB |
Output is correct |
16 |
Correct |
356 ms |
167752 KB |
Output is correct |
17 |
Correct |
348 ms |
164796 KB |
Output is correct |
18 |
Correct |
310 ms |
165784 KB |
Output is correct |
19 |
Correct |
36 ms |
112808 KB |
Output is correct |
20 |
Correct |
161 ms |
138180 KB |
Output is correct |
21 |
Correct |
319 ms |
162432 KB |
Output is correct |
22 |
Correct |
311 ms |
167748 KB |
Output is correct |
23 |
Correct |
414 ms |
176572 KB |
Output is correct |
24 |
Correct |
317 ms |
167704 KB |
Output is correct |
25 |
Correct |
330 ms |
164656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
124484 KB |
Output is correct |
2 |
Runtime error |
2234 ms |
681700 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
124484 KB |
Output is correct |
2 |
Runtime error |
2234 ms |
681700 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
109904 KB |
Output is correct |
2 |
Correct |
25 ms |
109824 KB |
Output is correct |
3 |
Correct |
25 ms |
109904 KB |
Output is correct |
4 |
Correct |
26 ms |
109916 KB |
Output is correct |
5 |
Correct |
27 ms |
109908 KB |
Output is correct |
6 |
Correct |
26 ms |
110060 KB |
Output is correct |
7 |
Correct |
26 ms |
109904 KB |
Output is correct |
8 |
Correct |
25 ms |
109916 KB |
Output is correct |
9 |
Correct |
25 ms |
109916 KB |
Output is correct |
10 |
Correct |
25 ms |
110032 KB |
Output is correct |
11 |
Correct |
26 ms |
109940 KB |
Output is correct |
12 |
Correct |
26 ms |
110068 KB |
Output is correct |
13 |
Correct |
25 ms |
109916 KB |
Output is correct |
14 |
Correct |
25 ms |
109904 KB |
Output is correct |
15 |
Correct |
25 ms |
109992 KB |
Output is correct |
16 |
Correct |
27 ms |
109912 KB |
Output is correct |
17 |
Correct |
30 ms |
110164 KB |
Output is correct |
18 |
Correct |
25 ms |
109916 KB |
Output is correct |
19 |
Correct |
26 ms |
110160 KB |
Output is correct |
20 |
Correct |
1479 ms |
241944 KB |
Output is correct |
21 |
Correct |
1485 ms |
258748 KB |
Output is correct |
22 |
Correct |
1016 ms |
239940 KB |
Output is correct |
23 |
Correct |
904 ms |
224624 KB |
Output is correct |
24 |
Correct |
996 ms |
239492 KB |
Output is correct |
25 |
Correct |
1871 ms |
282320 KB |
Output is correct |
26 |
Correct |
1173 ms |
239900 KB |
Output is correct |
27 |
Correct |
2094 ms |
321840 KB |
Output is correct |
28 |
Correct |
787 ms |
184800 KB |
Output is correct |
29 |
Correct |
490 ms |
168496 KB |
Output is correct |
30 |
Correct |
1783 ms |
295028 KB |
Output is correct |
31 |
Correct |
378 ms |
166212 KB |
Output is correct |
32 |
Correct |
337 ms |
168116 KB |
Output is correct |
33 |
Correct |
356 ms |
167752 KB |
Output is correct |
34 |
Correct |
348 ms |
164796 KB |
Output is correct |
35 |
Correct |
310 ms |
165784 KB |
Output is correct |
36 |
Correct |
36 ms |
112808 KB |
Output is correct |
37 |
Correct |
161 ms |
138180 KB |
Output is correct |
38 |
Correct |
319 ms |
162432 KB |
Output is correct |
39 |
Correct |
311 ms |
167748 KB |
Output is correct |
40 |
Correct |
414 ms |
176572 KB |
Output is correct |
41 |
Correct |
317 ms |
167704 KB |
Output is correct |
42 |
Correct |
330 ms |
164656 KB |
Output is correct |
43 |
Correct |
106 ms |
124484 KB |
Output is correct |
44 |
Runtime error |
2234 ms |
681700 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |