結果

問題 No.867 避難経路
ユーザー mencottonmencotton
提出日時 2019-08-17 00:02:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,806 bytes
コンパイル時間 1,726 ms
コンパイル使用メモリ 96,096 KB
実行使用メモリ 14,672 KB
最終ジャッジ日時 2023-10-24 11:51:11
合計ジャッジ時間 13,660 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 OLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

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<ll, ll>>>> dp;

void bfs(vector<ll> start) {
    priority_queue<vector<ll>, vector<vector<ll>>, 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<ll> 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<ll, ll>>>>
            (h, vector<vector<pair<ll, ll>>>(w, vector<pair<ll, ll>>{{0, 1145141919810364}}));
    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]) {
            cout << k * k << endl;
            cout << k * k * usi.first << endl;
            ret = min(ret, k * k * usi.first + usi.second);
        }

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