Submission #472901

# Submission time Handle Problem Language Result Execution time Memory
472901 2021-09-14T13:21:12 Z dxz05 Sky Walking (IOI19_walk) C++14
10 / 100
4000 ms 1048576 KB
#pragma GCC optimize("Ofast,O2,O3")
#pragma GCC target("avx,avx2")

#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:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 0; i < y.size(); i++){
      |                     ~~^~~~~~~~~~
walk.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     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:69: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]
   69 |         for (int j = 1; j < points[i].size(); j++){
      |                         ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 111 ms 188152 KB Output is correct
2 Correct 109 ms 188060 KB Output is correct
3 Correct 109 ms 188064 KB Output is correct
4 Correct 112 ms 188228 KB Output is correct
5 Correct 119 ms 188216 KB Output is correct
6 Correct 112 ms 188248 KB Output is correct
7 Correct 108 ms 188228 KB Output is correct
8 Correct 108 ms 188112 KB Output is correct
9 Correct 112 ms 188196 KB Output is correct
10 Correct 115 ms 188228 KB Output is correct
11 Correct 111 ms 188200 KB Output is correct
12 Correct 108 ms 188184 KB Output is correct
13 Correct 113 ms 188192 KB Output is correct
14 Correct 112 ms 188100 KB Output is correct
15 Correct 108 ms 188180 KB Output is correct
16 Correct 108 ms 188228 KB Output is correct
17 Correct 117 ms 188304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 188068 KB Output is correct
2 Correct 112 ms 188228 KB Output is correct
3 Correct 1186 ms 289292 KB Output is correct
4 Correct 1145 ms 305100 KB Output is correct
5 Correct 660 ms 289948 KB Output is correct
6 Correct 1161 ms 278492 KB Output is correct
7 Correct 673 ms 290080 KB Output is correct
8 Correct 1503 ms 317588 KB Output is correct
9 Correct 798 ms 286984 KB Output is correct
10 Correct 1426 ms 346888 KB Output is correct
11 Correct 634 ms 244668 KB Output is correct
12 Correct 419 ms 234652 KB Output is correct
13 Correct 1157 ms 327388 KB Output is correct
14 Correct 2992 ms 228664 KB Output is correct
15 Correct 1623 ms 224492 KB Output is correct
16 Correct 368 ms 225724 KB Output is correct
17 Correct 351 ms 224588 KB Output is correct
18 Execution timed out 4073 ms 206496 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 167 ms 200864 KB Output is correct
2 Runtime error 3987 ms 1048576 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 167 ms 200864 KB Output is correct
2 Runtime error 3987 ms 1048576 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 111 ms 188152 KB Output is correct
2 Correct 109 ms 188060 KB Output is correct
3 Correct 109 ms 188064 KB Output is correct
4 Correct 112 ms 188228 KB Output is correct
5 Correct 119 ms 188216 KB Output is correct
6 Correct 112 ms 188248 KB Output is correct
7 Correct 108 ms 188228 KB Output is correct
8 Correct 108 ms 188112 KB Output is correct
9 Correct 112 ms 188196 KB Output is correct
10 Correct 115 ms 188228 KB Output is correct
11 Correct 111 ms 188200 KB Output is correct
12 Correct 108 ms 188184 KB Output is correct
13 Correct 113 ms 188192 KB Output is correct
14 Correct 112 ms 188100 KB Output is correct
15 Correct 108 ms 188180 KB Output is correct
16 Correct 108 ms 188228 KB Output is correct
17 Correct 117 ms 188304 KB Output is correct
18 Correct 116 ms 188068 KB Output is correct
19 Correct 112 ms 188228 KB Output is correct
20 Correct 1186 ms 289292 KB Output is correct
21 Correct 1145 ms 305100 KB Output is correct
22 Correct 660 ms 289948 KB Output is correct
23 Correct 1161 ms 278492 KB Output is correct
24 Correct 673 ms 290080 KB Output is correct
25 Correct 1503 ms 317588 KB Output is correct
26 Correct 798 ms 286984 KB Output is correct
27 Correct 1426 ms 346888 KB Output is correct
28 Correct 634 ms 244668 KB Output is correct
29 Correct 419 ms 234652 KB Output is correct
30 Correct 1157 ms 327388 KB Output is correct
31 Correct 2992 ms 228664 KB Output is correct
32 Correct 1623 ms 224492 KB Output is correct
33 Correct 368 ms 225724 KB Output is correct
34 Correct 351 ms 224588 KB Output is correct
35 Execution timed out 4073 ms 206496 KB Time limit exceeded
36 Halted 0 ms 0 KB -