結果

問題 No.34 砂漠の行商人
ユーザー 👑 colognecologne
提出日時 2022-01-23 17:01:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 722 ms / 5,000 ms
コード長 1,037 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 81,900 KB
実行使用メモリ 207,108 KB
最終ジャッジ日時 2024-05-07 05:26:25
合計ジャッジ時間 4,344 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
53,816 KB
testcase_01 AC 44 ms
54,504 KB
testcase_02 AC 70 ms
69,256 KB
testcase_03 AC 44 ms
54,260 KB
testcase_04 AC 134 ms
80,912 KB
testcase_05 AC 152 ms
82,676 KB
testcase_06 AC 74 ms
74,084 KB
testcase_07 AC 184 ms
86,292 KB
testcase_08 AC 239 ms
93,732 KB
testcase_09 AC 46 ms
61,648 KB
testcase_10 AC 47 ms
61,240 KB
testcase_11 AC 47 ms
61,840 KB
testcase_12 AC 104 ms
79,836 KB
testcase_13 AC 47 ms
61,576 KB
testcase_14 AC 47 ms
62,776 KB
testcase_15 AC 48 ms
60,408 KB
testcase_16 AC 49 ms
60,848 KB
testcase_17 AC 47 ms
60,588 KB
testcase_18 AC 44 ms
55,404 KB
testcase_19 AC 509 ms
151,572 KB
testcase_20 AC 722 ms
207,108 KB
testcase_21 AC 89 ms
81,120 KB
testcase_22 AC 48 ms
60,568 KB
testcase_23 AC 48 ms
59,988 KB
testcase_24 AC 47 ms
61,852 KB
testcase_25 AC 156 ms
89,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import collections

input = sys.stdin.readline


def main():
    N, V, SX, SY, GX, GY = map(int, input().split())
    L = [list(map(int, input().split())) for i in range(N)]

    if V > (abs(SX-GX) + abs(SY-GY)) * 9:
        print(abs(SX-GX) + abs(SY-GY))
        return

    vis = [[[False]*(V+1) for i in range(N)] for i in range(N)]
    hp = [[0]*N for i in range(N)]

    Q = collections.deque([(0, SY-1, SX-1, V)])
    while len(Q) > 0:
        d, r, c, v = Q.popleft()
        if (r, c) == (GY-1, GX-1):
            print(d)
            return
        if vis[r][c][v]:
            continue
        vis[r][c][v] = True
        if hp[r][c] >= v:
            continue
        hp[r][c] = v
        for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            x, y = r+dx, c+dy
            if 0 <= x < N and 0 <= y < N and v > L[x][y]:
                nv = v-L[x][y]
                if not vis[x][y][nv] and hp[x][y] < nv:
                    Q.append((d+1, x, y, nv))

    print(-1)


if __name__ == '__main__':
    main()
0