Submission #1026892

# Submission time Handle Problem Language Result Execution time Memory
1026892 2024-07-18T13:05:23 Z Zicrus Sky Walking (IOI19_walk) C++17
10 / 100
4000 ms 66260 KB
#include <bits/stdc++.h>
#include "walk.h"
using namespace std;

typedef long long ll;

ll min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int t) {
    int N = x.size(), M = y.size();
    vector<pair<int, int>> pos;
    vector<vector<int>> adj;
    for (int j = 0; j < M; j++) {
        vector<int> buildings;
        for (int i = l[j]; i <= r[j]; i++) {
            if (y[j] <= h[i]) {
                buildings.push_back(x[i]);
            }
        }
        int g = adj.size();
        for (auto &e : buildings) {
            vector<int> a;
            int id = g - 1;
            for (auto &c : buildings) {
                id++;
                if (e == c) continue;
                a.push_back(id);
            }
            adj.push_back(a);
            pos.push_back({e, y[j]});
        }
    }
    adj.push_back({});
    adj.push_back({});
    pos.push_back({x[s], 0});
    pos.push_back({x[t], 0});

    vector<bool> vst(pos.size());
    vector<ll> dist(pos.size(), 1ll << 62);

    priority_queue<pair<int, int>> q;
    dist[pos.size()-2] = 0;
    q.push({0, pos.size()-2});
    while (!q.empty()) {
        int node = q.top().second; q.pop();
        if (vst[node]) continue;
        vst[node] = true;

        vector<int> ac = adj[node];
        for (int i = 0; i < pos.size(); i++) {
            if (i == node) continue;
            if (pos[i].first == pos[node].first) ac.push_back(i);
        }

        for (auto &e : ac) {
            dist[e] = min(dist[e], dist[node] + abs(pos[node].first - pos[e].first) + abs(pos[node].second - pos[e].second));
            q.push({-dist[e], e});
        }
    }

    return dist.back() == (1ll << 62) ? -1 : dist.back();
}

Compilation message

walk.cpp: In function 'll min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:48: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]
   48 |         for (int i = 0; i < pos.size(); i++) {
      |                         ~~^~~~~~~~~~~~
walk.cpp:8:9: warning: unused variable 'N' [-Wunused-variable]
    8 |     int N = x.size(), M = y.size();
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 6 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 4057 ms 66260 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4038 ms 9228 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4038 ms 9228 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 6 ms 604 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Execution timed out 4057 ms 66260 KB Time limit exceeded
21 Halted 0 ms 0 KB -