結果

問題 No.1283 Extra Fee
ユーザー oevloevl
提出日時 2020-11-06 23:40:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,174 bytes
コンパイル時間 1,939 ms
コンパイル使用メモリ 218,136 KB
実行使用メモリ 22,164 KB
最終ジャッジ日時 2024-04-27 23:26:26
合計ジャッジ時間 6,880 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 11 ms
6,940 KB
testcase_12 AC 13 ms
6,944 KB
testcase_13 AC 10 ms
6,944 KB
testcase_14 AC 44 ms
6,940 KB
testcase_15 AC 71 ms
7,680 KB
testcase_16 AC 15 ms
6,940 KB
testcase_17 AC 165 ms
20,704 KB
testcase_18 AC 251 ms
17,920 KB
testcase_19 AC 276 ms
18,560 KB
testcase_20 AC 251 ms
17,664 KB
testcase_21 AC 255 ms
17,792 KB
testcase_22 AC 229 ms
16,256 KB
testcase_23 AC 218 ms
19,072 KB
testcase_24 AC 276 ms
18,944 KB
testcase_25 AC 281 ms
19,072 KB
testcase_26 AC 282 ms
19,200 KB
testcase_27 AC 284 ms
19,072 KB
testcase_28 AC 285 ms
19,072 KB
testcase_29 AC 180 ms
22,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using Tup = tuple<long long, int, int, int>;

const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
const long long INF = 1e18;

int main() {
    int n, m;
    cin >> n >> m;
    vector cost(n, vector<long long>(n));
    for(int i = 0; i < m; ++i) {
        int h, w, c;
        cin >> h >> w >> c;
        h--, w--;
        cost[h][w] = c;
    }

    priority_queue<Tup, vector<Tup>, greater<Tup>> que;
    vector dist(n, vector(n, vector<long long>(2, INF)));

    auto push = [&](long long c, int y, int x, int t) {
        if(dist[y][x][t] <= c) return;
        que.emplace(c, y, x, t);
        dist[y][x][t] = c;
    };
    push(0, 0, 0, 0);
    while(!que.empty()) {
        auto[c, y, x, t] = que.top(); que.pop();
        for(int i = 0; i < 4; ++i) {
            int ny = y + dy[i], nx = x + dx[i];
            if(ny < 0 || nx < 0 || ny >= n || nx >= n) continue;
            if(t == 0) push(dist[y][x][t] + 1, ny, nx, 1);
            push(dist[y][x][t] + cost[ny][nx] + 1, ny, nx, t);
        }
    }
    cout << dist[n - 1][n - 1][1] << '\n';
    return 0;
}
0