結果

問題 No.867 避難経路
ユーザー mencottonmencotton
提出日時 2019-08-16 23:50:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,707 bytes
コンパイル時間 1,294 ms
コンパイル使用メモリ 92,116 KB
実行使用メモリ 14,212 KB
最終ジャッジ日時 2023-10-24 10:06:35
合計ジャッジ時間 42,717 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1,303 ms
10,944 KB
testcase_16 AC 1,451 ms
12,660 KB
testcase_17 AC 1,299 ms
10,428 KB
testcase_18 AC 1,437 ms
12,440 KB
testcase_19 AC 1,438 ms
12,528 KB
testcase_20 AC 1,406 ms
12,340 KB
testcase_21 AC 1,469 ms
13,408 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1,090 ms
7,868 KB
testcase_32 AC 1,097 ms
7,868 KB
testcase_33 AC 1,092 ms
7,868 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 2 ms
4,372 KB
testcase_42 AC 2 ms
4,372 KB
testcase_43 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;

int h, w;
vector<vector<int>> ban;
vector<vector<vector<pair<int, int>>>> dp;

void bfs(vector<int> start) {
    priority_queue<vector<int>, vector<vector<int>>, greater<>> que;
    que.push(start);

    vector<int> mx{1, -1, 0, 0};
    vector<int> my{0, 0, 1, -1};
    while (true) {
        if (que.empty())break;

        vector<int> now = que.top();
        que.pop();
        auto &v = dp[now[2]][now[3]];
        if (now[1] >= v[v.size() - 1].second)continue;

        v.push_back({now[0], now[1]});
        for (int i = 0; i < 4; i++) {
            int ax = now[2] + mx[i];
            int ay = now[3] + my[i];
            if (0 <= ax && ax < h && 0 <= ay && ay < w) {
                auto nv = dp[ax][ay];
                if (now[1] + ban[ax][ay] < nv[nv.size() - 1].second)
                    que.push({now[0] + 1, now[1] + ban[ax][ay], ax, ay});
            }
        }
    }
}

int main() {
    int gx, gy;
    cin >> h >> w >> gx >> gy;
    gx--;
    gy--;
    ban = vector<vector<int>>(h, vector<int>(w));
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)cin >> ban[i][j];

    dp = vector<vector<vector<pair<int, int>>>>
            (h, vector<vector<pair<int, int>>>(w, vector<pair<int, int>>{{-1, 1145141919}}));
    bfs({1, ban[gx][gy], gx, gy});

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        ll x, y, k;
        cin >> x >> y >> k;
        x--;
        y--;
        ll ret = 1145141919810364364;
        for (auto usi:dp[x][y]) ret = min(ret, k * k * usi.first + usi.second);

        cout << ret << endl;
    }
    return 0;
}
0