답안 #1076343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076343 2024-08-26T13:09:35 Z j_vdd16 Sky Walking (IOI19_walk) C++17
24 / 100
2273 ms 1048576 KB
#include "walk.h"

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;

struct SegTree {
    int n, N;
    vi tree;
    int def = LLONG_MAX / 2;

    SegTree(vi values) {
        n = values.size();
        N = 1;
        while (N < n) N *= 2;

        tree = vi(2 * N, def);
        loop(i, n) {
            tree[N + i] = values[i];
        }

        for (int i = N - 1; i >= 1; i--) {
            tree[i] = merge(tree[2 * i], tree[2 * i + 1]);
        }
    }

    int merge(int a, int b) {
        return min(a, b);
    }

    void set(int idx, int v) {
        idx += N;
        tree[idx] = v;
        idx /= 2;

        while (idx) {
            tree[idx] = merge(tree[idx * 2], tree[idx * 2 + 1]);
            idx /= 2;
        }
    }

    int get(int l, int r, int i = 1, int tl = 0, int tr = -1) {
        if (tr == -1) {
            tr = N;
        }

        if (tr <= l || tl >= r) {
            return def;
        }

        if (tl >= l && tr <= r) {
            return tree[i];
        }

        int tm = (tl + tr) / 2;
        return merge(get(l, r, i * 2, tl, tm), get(l, r, i * 2 + 1, tm, tr));
    }
};

long long min_distance(std::vector<signed> xs, std::vector<signed> hs, std::vector<signed> ls, std::vector<signed> rs, std::vector<signed> ys, signed s, signed g) {
    int n = xs.size();
    int m = ls.size();

    vector<tuple<int, int, int>> bridges(m);
    loop(i, m) {
        bridges[i] = { ys[i], ls[i], rs[i] };
    }
    sort(all(bridges));
    sort(all(ys));

    vii buildings(n);
    loop(i, n) {
        buildings[i] = { xs[i], hs[i] };
    }
    //sort(all(buildings));

    int nodes = 0;
    vvii adj = { };

    vvii open(n), close(n);
    loop(i, m) {
        auto [y, l, r] = bridges[i];

        open[l].push_back({y, i});
        close[r].push_back({y, i});
    }

    int start = -1, end = -1;

    map<ii, ii> cur;
    for (int i = 0; i < n; i++) {
        for (auto [y, j] : open[i]) {
            cur[{y, j}] = {nodes++, xs[i]};
            adj.push_back({});
        }

        int prevNode = nodes++;
        adj.push_back({});
        if (i == s) {
            start = prevNode;
        }
        if (i == g) {
            end = prevNode;
        }

        int prevY = 0;
        for (auto& [f, f2] : cur) {
            auto [y, j] = f;
            if (y > buildings[i].second) break;

            auto& [idx, x] = f2;
            int node = idx;
            if (x != xs[i]) {
                node = nodes++;
                adj.push_back({});

                adj[idx].push_back({node, xs[i] - x});
                adj[node].push_back({idx, xs[i] - x});
            }
            adj[prevNode].push_back({ node, y - prevY });
            adj[node].push_back({ prevNode, y - prevY });

            idx = node;
            x = xs[i];

            prevY = y;
            prevNode = node;
        }

        for (auto [y, j] : close[i]) {
            cur.erase({y, j});
        }
    }

    vb vis(nodes, false);
    priority_queue<ii, vii, greater<ii>> q;
    q.push({0, start});

    int res = -1;
    while (q.size()) {
        auto [dist, node] = q.top();
        q.pop();

        if (node == end) {
            res = dist;
            break;
        }

        if (vis[node]) continue;
        vis[node] = true;

        for (auto [child, weight] : adj[node]) {
            q.push({dist + weight, child});
        }
    }

    return res;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 200 ms 84360 KB Output is correct
4 Correct 486 ms 98088 KB Output is correct
5 Correct 202 ms 84916 KB Output is correct
6 Correct 204 ms 80336 KB Output is correct
7 Correct 181 ms 85224 KB Output is correct
8 Correct 276 ms 104840 KB Output is correct
9 Correct 238 ms 84528 KB Output is correct
10 Correct 685 ms 148324 KB Output is correct
11 Correct 176 ms 52980 KB Output is correct
12 Correct 129 ms 49232 KB Output is correct
13 Correct 571 ms 115916 KB Output is correct
14 Correct 116 ms 47236 KB Output is correct
15 Correct 117 ms 48500 KB Output is correct
16 Correct 123 ms 47356 KB Output is correct
17 Correct 115 ms 46580 KB Output is correct
18 Correct 140 ms 50188 KB Output is correct
19 Correct 5 ms 2456 KB Output is correct
20 Correct 61 ms 24072 KB Output is correct
21 Correct 100 ms 46332 KB Output is correct
22 Correct 118 ms 48128 KB Output is correct
23 Correct 206 ms 61088 KB Output is correct
24 Correct 141 ms 47612 KB Output is correct
25 Correct 113 ms 46836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 17944 KB Output is correct
2 Correct 2273 ms 536656 KB Output is correct
3 Runtime error 1320 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 17944 KB Output is correct
2 Correct 2273 ms 536656 KB Output is correct
3 Runtime error 1320 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 200 ms 84360 KB Output is correct
21 Correct 486 ms 98088 KB Output is correct
22 Correct 202 ms 84916 KB Output is correct
23 Correct 204 ms 80336 KB Output is correct
24 Correct 181 ms 85224 KB Output is correct
25 Correct 276 ms 104840 KB Output is correct
26 Correct 238 ms 84528 KB Output is correct
27 Correct 685 ms 148324 KB Output is correct
28 Correct 176 ms 52980 KB Output is correct
29 Correct 129 ms 49232 KB Output is correct
30 Correct 571 ms 115916 KB Output is correct
31 Correct 116 ms 47236 KB Output is correct
32 Correct 117 ms 48500 KB Output is correct
33 Correct 123 ms 47356 KB Output is correct
34 Correct 115 ms 46580 KB Output is correct
35 Correct 140 ms 50188 KB Output is correct
36 Correct 5 ms 2456 KB Output is correct
37 Correct 61 ms 24072 KB Output is correct
38 Correct 100 ms 46332 KB Output is correct
39 Correct 118 ms 48128 KB Output is correct
40 Correct 206 ms 61088 KB Output is correct
41 Correct 141 ms 47612 KB Output is correct
42 Correct 113 ms 46836 KB Output is correct
43 Correct 50 ms 17944 KB Output is correct
44 Correct 2273 ms 536656 KB Output is correct
45 Runtime error 1320 ms 1048576 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -