結果

問題 No.2695 Warp Zone
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-03-23 04:51:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,479 bytes
コンパイル時間 2,776 ms
コンパイル使用メモリ 212,300 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2024-03-23 04:51:16
合計ジャッジ時間 4,719 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 46 ms
34,816 KB
testcase_04 AC 44 ms
33,536 KB
testcase_05 AC 45 ms
33,536 KB
testcase_06 AC 45 ms
34,560 KB
testcase_07 AC 45 ms
34,816 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 17 ms
13,568 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 6 ms
6,676 KB
testcase_12 AC 22 ms
18,048 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 28 ms
22,400 KB
testcase_15 AC 14 ms
12,160 KB
testcase_16 AC 5 ms
6,676 KB
testcase_17 AC 10 ms
8,448 KB
testcase_18 AC 34 ms
27,136 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 30 ms
24,448 KB
testcase_21 AC 27 ms
22,016 KB
testcase_22 AC 12 ms
11,136 KB
testcase_23 AC 22 ms
17,920 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    long long h, w;
    cin >> h >> w >> n;

    vector<pair<long long, long long>> points{{1, 1}, {h, w}};
    vector<vector<long long>> dist(2 * n + 2, vector<long long>(2 * n + 2, 0));
    for (int i = 0; i < n; i++) {
        long long a, b, c, d;
        cin >> a >> b >> c >> d;
        points.push_back({a, b});
        points.push_back({c, d});
        dist[2 * i + 2][2 * i + 3] = 1;
    }
    for (int i = 0; i < 2 * n + 2; i++) {
        for (int j = 0; j < 2 * n + 2; j++) {
            if (dist[i][j]) {
                continue;
            }
            dist[i][j] = abs(points[i].first - points[j].first) +
                         abs(points[i].second - points[j].second);
        }
    }
    const long long INF = 1e18;
    vector<bool> vis(2 * n + 2, false);
    vector<long long> ans(2 * n + 2, INF);
    ans[0] = 0;
    for (int i = 0; i < 2 * n + 2; i++) {
        int v = -1;
        long long ma = INF;
        for (int j = 0; j < 2 * n + 2; j++) {
            if (!vis[j] && ans[j] < ma) {
                ma = ans[j];
                v = j;
            }
        }
        if (v == -1) {
            break;
        }
        vis[v] = true;
        for (int u = 0; u < 2 * n + 2; u++) {
            ans[u] = min(ans[u], ans[v] + dist[v][u]);
        }
    }
    cout << ans[1] << endl;
}
0