# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
298499 |
2020-09-13T03:23:25 Z |
JPN20 |
Sky Walking (IOI19_walk) |
C++17 |
|
241 ms |
31600 KB |
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
// Input
long long N, X[1 << 18], H[1 << 18];
long long M, L[1 << 18], R[1 << 18], Y[1 << 18];
long long SX, GX;
// Compress
vector<pair<int, int>> V[1 << 18][2];
set<tuple<int, int, long long>> Set;
void add(int height, int idx, int lim) {
auto itr = Set.lower_bound(make_tuple(height, idx, 0LL));
long long res = (1LL << 60);
if (itr != Set.end()) {
tuple<int, int, long long> val1 = (*itr);
res = min(res, get<2>(val1) + abs(height - get<0>(val1)));
}
if (itr != Set.begin()) {
itr--;
tuple<int, int, long long> val2 = (*itr);
res = min(res, get<2>(val2) + abs(height - get<0>(val2)));
}
Set.insert(make_tuple(height, idx, res));
}
void lose(int height, int idx) {
auto itr = Set.lower_bound(make_tuple(height, idx, 0LL));
Set.erase(itr);
}
long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g) {
N = x.size();
M = l.size();
SX = s;
GX = g;
for (int i = 0; i < N; i++) X[i] = x[i];
for (int i = 0; i < N; i++) H[i] = h[i];
for (int i = 0; i < M; i++) L[i] = l[i];
for (int i = 0; i < M; i++) R[i] = r[i];
for (int i = 0; i < M; i++) Y[i] = y[i];
// Step #1. Maeshori
V[0][1].push_back(make_pair(0, -1));
for (int i = 0; i < M; i++) V[L[i]][0].push_back(make_pair(Y[i], i));
for (int i = 0; i < M; i++) V[R[i]][1].push_back(make_pair(Y[i], i));
for (int i = 0; i < N; i++) sort(V[i][0].begin(), V[i][0].end());
for (int i = 0; i < N; i++) sort(V[i][1].begin(), V[i][1].end());
// Step #2. Compress
Set.insert(make_tuple(0, -1, 0LL));
for (int i = 0; i < N; i++) {
for (int j = 0; j < (int)V[i][0].size(); j++) add(V[i][0][j].first, V[i][0][j].second, H[i]);
if (i == N - 1) break;
for (int j = 0; j < (int)V[i][1].size(); j++) lose(V[i][1][j].first, V[i][1][j].second);
}
// Step #3. Get Answer
long long Answer = (1LL << 60);
auto itr = Set.begin();
while (itr != Set.end()) {
Answer = min(Answer, get<0>(*itr) + get<2>(*itr));
itr++;
}
// Step #4. Output
if (Answer == (1LL << 60)) return -1;
return Answer + (X[N - 1] - X[0]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
16760 KB |
Output is correct |
2 |
Correct |
110 ms |
19816 KB |
Output is correct |
3 |
Correct |
129 ms |
20600 KB |
Output is correct |
4 |
Correct |
187 ms |
25080 KB |
Output is correct |
5 |
Correct |
229 ms |
30072 KB |
Output is correct |
6 |
Correct |
210 ms |
27508 KB |
Output is correct |
7 |
Correct |
109 ms |
21112 KB |
Output is correct |
8 |
Correct |
150 ms |
26872 KB |
Output is correct |
9 |
Correct |
207 ms |
28784 KB |
Output is correct |
10 |
Correct |
141 ms |
27632 KB |
Output is correct |
11 |
Correct |
26 ms |
14200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
16760 KB |
Output is correct |
2 |
Correct |
110 ms |
19816 KB |
Output is correct |
3 |
Correct |
129 ms |
20600 KB |
Output is correct |
4 |
Correct |
187 ms |
25080 KB |
Output is correct |
5 |
Correct |
229 ms |
30072 KB |
Output is correct |
6 |
Correct |
210 ms |
27508 KB |
Output is correct |
7 |
Correct |
109 ms |
21112 KB |
Output is correct |
8 |
Correct |
150 ms |
26872 KB |
Output is correct |
9 |
Correct |
207 ms |
28784 KB |
Output is correct |
10 |
Correct |
141 ms |
27632 KB |
Output is correct |
11 |
Correct |
26 ms |
14200 KB |
Output is correct |
12 |
Correct |
128 ms |
20600 KB |
Output is correct |
13 |
Correct |
194 ms |
25080 KB |
Output is correct |
14 |
Correct |
229 ms |
29944 KB |
Output is correct |
15 |
Correct |
170 ms |
25340 KB |
Output is correct |
16 |
Correct |
170 ms |
25080 KB |
Output is correct |
17 |
Correct |
168 ms |
25340 KB |
Output is correct |
18 |
Correct |
160 ms |
25080 KB |
Output is correct |
19 |
Correct |
174 ms |
25208 KB |
Output is correct |
20 |
Correct |
119 ms |
21112 KB |
Output is correct |
21 |
Correct |
49 ms |
15992 KB |
Output is correct |
22 |
Correct |
141 ms |
22904 KB |
Output is correct |
23 |
Correct |
145 ms |
23288 KB |
Output is correct |
24 |
Correct |
151 ms |
24696 KB |
Output is correct |
25 |
Correct |
137 ms |
23160 KB |
Output is correct |
26 |
Correct |
158 ms |
27000 KB |
Output is correct |
27 |
Correct |
241 ms |
29304 KB |
Output is correct |
28 |
Correct |
175 ms |
24696 KB |
Output is correct |
29 |
Correct |
221 ms |
27380 KB |
Output is correct |
30 |
Correct |
115 ms |
21248 KB |
Output is correct |
31 |
Correct |
211 ms |
28784 KB |
Output is correct |
32 |
Correct |
133 ms |
26128 KB |
Output is correct |
33 |
Correct |
140 ms |
27128 KB |
Output is correct |
34 |
Correct |
147 ms |
29688 KB |
Output is correct |
35 |
Correct |
150 ms |
28920 KB |
Output is correct |
36 |
Correct |
146 ms |
28152 KB |
Output is correct |
37 |
Correct |
129 ms |
27128 KB |
Output is correct |
38 |
Correct |
141 ms |
30000 KB |
Output is correct |
39 |
Correct |
172 ms |
31600 KB |
Output is correct |
40 |
Correct |
138 ms |
29304 KB |
Output is correct |
41 |
Correct |
132 ms |
27768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |