# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
472900 |
2021-09-14T13:19:40 Z |
dxz05 |
Sky Walking (IOI19_walk) |
C++14 |
|
4000 ms |
1048576 KB |
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MP make_pair
const int MAXN = 2e6 + 3e2;
void sort(vector<int> &l, vector<int> &r, vector<int> &y){
vector<pair<int, pair<int, int>>> vec(y.size());
for (int i = 0; i < y.size(); i++){
vec[i] = MP(y[i], MP(l[i], r[i]));
}
sort(vec.begin(), vec.end());
for (int i = 0; i < y.size(); i++){
y[i] = vec[i].first;
l[i] = vec[i].second.first;
r[i] = vec[i].second.second;
}
}
map<int, int> mp[MAXN];
int next_id = 0;
vector<pair<int, int>> points[MAXN];
int id(int i, int h){
if (mp[i].find(h) != mp[i].end()) return mp[i][h];
return mp[i][h] = next_id++;
}
vector<pair<int, int>> g[MAXN];
long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int start, int finish) {
int n = x.size(), m = y.size();
sort(l, r, y);
for (int i = 0; i < n; i++){
points[i].emplace_back(id(i, 0), 0);
}
for (int i = 0; i < m; i++){
//cout << l[i] << ' ' << r[i] << ' ' << y[i] << endl;
int last = l[i];
for (int j = l[i]; j <= r[i]; j++){
if (y[i] > h[j]) continue;
int a = id(j, y[i]);
points[j].emplace_back(a, y[i]);
if (j > l[i]) {
int b = id(last, y[i]);
g[a].emplace_back(b, x[j] - x[last]);
g[b].emplace_back(a, x[j] - x[last]);
}
last = j;
}
}
for (int i = 0; i < n; i++){
if (points[i].back().second != h[i]) points[i].emplace_back(id(i, h[i]), h[i]);
// cout << i << endl;
for (int j = 1; j < points[i].size(); j++){
// cout << points[i][j].first << ' ' << points[i][j].second << endl;
int a = points[i][j - 1].first, b = points[i][j].first, w = points[i][j].second - points[i][j - 1].second;
assert(w >= 0);
g[a].emplace_back(b, w);
g[b].emplace_back(a, w);
}
}
int k = next_id;
vector<ll> d(k, 1e18);
vector<bool> processed(k, false);
d[start] = 0;
priority_queue<pair<ll, int>> pq;
pq.push(MP(0, start));
while (!pq.empty()){
int v = pq.top().second; pq.pop();
if (processed[v]) continue;
processed[v] = true;
for (auto e : g[v]){
int u = e.first, w = e.second;
if (d[u] > d[v] + w){
d[u] = d[v] + w;
pq.push(MP(-d[u], u));
}
}
}
if (!processed[finish]) return -1;
return d[finish];
}
Compilation message
walk.cpp: In function 'void sort(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
walk.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int i = 0; i < y.size(); i++){
| ~~^~~~~~~~~~
walk.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i < y.size(); i++){
| ~~^~~~~~~~~~
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int j = 1; j < points[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
188100 KB |
Output is correct |
2 |
Correct |
100 ms |
188156 KB |
Output is correct |
3 |
Correct |
101 ms |
188100 KB |
Output is correct |
4 |
Correct |
101 ms |
188100 KB |
Output is correct |
5 |
Correct |
104 ms |
188204 KB |
Output is correct |
6 |
Correct |
108 ms |
188240 KB |
Output is correct |
7 |
Correct |
101 ms |
188228 KB |
Output is correct |
8 |
Correct |
104 ms |
188168 KB |
Output is correct |
9 |
Correct |
102 ms |
188108 KB |
Output is correct |
10 |
Correct |
100 ms |
188236 KB |
Output is correct |
11 |
Correct |
104 ms |
188276 KB |
Output is correct |
12 |
Correct |
102 ms |
188156 KB |
Output is correct |
13 |
Correct |
103 ms |
188100 KB |
Output is correct |
14 |
Correct |
103 ms |
188120 KB |
Output is correct |
15 |
Correct |
101 ms |
188136 KB |
Output is correct |
16 |
Correct |
105 ms |
188132 KB |
Output is correct |
17 |
Correct |
105 ms |
188280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
188072 KB |
Output is correct |
2 |
Correct |
103 ms |
188112 KB |
Output is correct |
3 |
Correct |
1165 ms |
289200 KB |
Output is correct |
4 |
Correct |
996 ms |
304816 KB |
Output is correct |
5 |
Correct |
669 ms |
289792 KB |
Output is correct |
6 |
Correct |
1311 ms |
278476 KB |
Output is correct |
7 |
Correct |
655 ms |
289868 KB |
Output is correct |
8 |
Correct |
1459 ms |
319504 KB |
Output is correct |
9 |
Correct |
789 ms |
290416 KB |
Output is correct |
10 |
Correct |
1307 ms |
350516 KB |
Output is correct |
11 |
Correct |
607 ms |
247340 KB |
Output is correct |
12 |
Correct |
432 ms |
238516 KB |
Output is correct |
13 |
Correct |
1132 ms |
331180 KB |
Output is correct |
14 |
Correct |
3790 ms |
232244 KB |
Output is correct |
15 |
Correct |
2004 ms |
227552 KB |
Output is correct |
16 |
Correct |
357 ms |
228432 KB |
Output is correct |
17 |
Correct |
347 ms |
226904 KB |
Output is correct |
18 |
Execution timed out |
4074 ms |
207316 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
200684 KB |
Output is correct |
2 |
Execution timed out |
4131 ms |
1048576 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
200684 KB |
Output is correct |
2 |
Execution timed out |
4131 ms |
1048576 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
188100 KB |
Output is correct |
2 |
Correct |
100 ms |
188156 KB |
Output is correct |
3 |
Correct |
101 ms |
188100 KB |
Output is correct |
4 |
Correct |
101 ms |
188100 KB |
Output is correct |
5 |
Correct |
104 ms |
188204 KB |
Output is correct |
6 |
Correct |
108 ms |
188240 KB |
Output is correct |
7 |
Correct |
101 ms |
188228 KB |
Output is correct |
8 |
Correct |
104 ms |
188168 KB |
Output is correct |
9 |
Correct |
102 ms |
188108 KB |
Output is correct |
10 |
Correct |
100 ms |
188236 KB |
Output is correct |
11 |
Correct |
104 ms |
188276 KB |
Output is correct |
12 |
Correct |
102 ms |
188156 KB |
Output is correct |
13 |
Correct |
103 ms |
188100 KB |
Output is correct |
14 |
Correct |
103 ms |
188120 KB |
Output is correct |
15 |
Correct |
101 ms |
188136 KB |
Output is correct |
16 |
Correct |
105 ms |
188132 KB |
Output is correct |
17 |
Correct |
105 ms |
188280 KB |
Output is correct |
18 |
Correct |
103 ms |
188072 KB |
Output is correct |
19 |
Correct |
103 ms |
188112 KB |
Output is correct |
20 |
Correct |
1165 ms |
289200 KB |
Output is correct |
21 |
Correct |
996 ms |
304816 KB |
Output is correct |
22 |
Correct |
669 ms |
289792 KB |
Output is correct |
23 |
Correct |
1311 ms |
278476 KB |
Output is correct |
24 |
Correct |
655 ms |
289868 KB |
Output is correct |
25 |
Correct |
1459 ms |
319504 KB |
Output is correct |
26 |
Correct |
789 ms |
290416 KB |
Output is correct |
27 |
Correct |
1307 ms |
350516 KB |
Output is correct |
28 |
Correct |
607 ms |
247340 KB |
Output is correct |
29 |
Correct |
432 ms |
238516 KB |
Output is correct |
30 |
Correct |
1132 ms |
331180 KB |
Output is correct |
31 |
Correct |
3790 ms |
232244 KB |
Output is correct |
32 |
Correct |
2004 ms |
227552 KB |
Output is correct |
33 |
Correct |
357 ms |
228432 KB |
Output is correct |
34 |
Correct |
347 ms |
226904 KB |
Output is correct |
35 |
Execution timed out |
4074 ms |
207316 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |