Submission #761106

# Submission time Handle Problem Language Result Execution time Memory
761106 2023-06-19T08:00:49 Z MinaRagy06 Sky Walking (IOI19_walk) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<int> adj[100'005], intersect[100'005];
map<int, ll> dist[100'005];
int sparse[17][200'005];
const ll INF = 1e18;
ll min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g) {
    int n = x.size(), m = l.size();
    for (int i = 0; i < n; i++) {
        sparse[0][i] = h[i];
    }
    for (int j = 1; j < 17; j++) {
        for (int i = 0; i < n; i++) {
            sparse[j][i] = max(sparse[j - 1][i], sparse[j - 1][i + (1 << (j - 1))]);
        }
    }
    for (int i = 0; i < m; i++) {
        int j = l[i];
        while (j <= r[i]) {
            if (y[i] <= h[j]) {
                adj[j].push_back(i);
                intersect[i].push_back(j);
                j++;
                continue;
            }
            int mx = 0;
            for (int k = 16; k >= 0; k--) {
                if (y[i] > max(mx, sparse[k][j])) {
                    mx = max(mx, sparse[k][j]);
                    j += (1 << k);
                }
            }
            if (j <= r[i]) {
                adj[j].push_back(i);
                intersect[i].push_back(j);
                j++;
            }
        }
        assert(intersect[i].size() <= 11);
    }
    y.push_back(0);
    priority_queue<pair<ll, pair<int, int>>> pq;
    pq.push({0, {s, m}});
    int updates = 0;
    while (pq.size()) {
        ll d = -pq.top().first;
        int i = pq.top().second.first;
        int j = y[pq.top().second.second];
        pq.pop();
        for (auto nxtedge : adj[i]) {
            for (auto nxt : intersect[nxtedge]) {
                ll newd = d + abs(j - y[nxtedge]) + abs(x[i] - x[nxt]);
                if (dist[nxt].find(nxtedge) == dist[nxt].end() || newd < dist[nxt][nxtedge]) {
                    if (dist[nxt].find(nxtedge) != dist[nxt].end()) updates++;
                    dist[nxt][nxtedge] = newd;
                    pq.push({-newd, {nxt, nxtedge}});
                }
            }
        }
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += dist[i].size();
    }
    ll ans = INF;
    for (int i = 0; i < m; i++) {
        if (dist[g].find(i) != dist[g].end()) {
            ans = min(ans, dist[g][i] + y[i]);
        }
    }
    if (ans >= INF) return -1;
    return ans;
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<int> X(N), H(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> H[i];
    }
    vector<int> L(M), R(M), Y(M);
    for (int i = 0; i < M; i++) {
        cin >> L[i] >> R[i] >> Y[i];
    }
    int S, G;
    cin >> S >> G;
    cout << min_distance(X, H, L, R, Y, S, G) << '\n';
    return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccuy8TkN.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccbLOzeM.o:walk.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status