結果

問題 No.971 いたずらっ子
ユーザー nebukuro09nebukuro09
提出日時 2020-01-17 21:33:41
言語 D
(dmd 2.105.2)
結果
TLE  
実行時間 -
コード長 1,125 bytes
コンパイル時間 971 ms
コンパイル使用メモリ 121,288 KB
実行使用メモリ 42,280 KB
最終ジャッジ日時 2023-09-04 04:40:20
合計ジャッジ時間 21,862 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 AC 1,835 ms
32,236 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 AC 1,689 ms
36,392 KB
testcase_07 AC 16 ms
4,380 KB
testcase_08 AC 556 ms
18,136 KB
testcase_09 AC 523 ms
12,592 KB
testcase_10 AC 15 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = iota(H).map!(_ => readln.chomp).array;

    auto pq = new BinaryHeap!(Array!(Tuple!(int, int, long)), "a[2] > b[2]");
    pq.insert(tuple(0, 0, 0L));
    auto dist = new long[][](H, W);
    foreach (i; 0..H) dist[i][] = 1L << 59;

    auto dr = [1, 0];
    auto dc = [0, 1];

    while (!pq.empty) {
        auto t = pq.front;
        pq.removeFront;
        auto r = t[0];
        auto c = t[1];
        auto d = t[2];
        if (dist[r][c] <= d) continue;
        dist[r][c] = d;
        foreach (i; 0..2) {
            auto nr = r + dr[i];
            auto nc = c + dc[i];
            if (nr >= H || nc >= W) continue;
            auto nd = A[nr][nc] == 'k' ? d + 1 + nr + nc : d + 1;
            if (dist[nr][nc] <= nd) continue;
            pq.insert(tuple(nr, nc, nd));
        }
    }

    dist[H-1][W-1].writeln;
}
0