結果

問題 No.34 砂漠の行商人
ユーザー 👑 colognecologne
提出日時 2022-01-23 17:01:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 736 ms / 5,000 ms
コード長 1,037 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 209,456 KB
最終ジャッジ日時 2023-08-19 22:23:04
合計ジャッジ時間 5,921 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,488 KB
testcase_01 AC 92 ms
71,624 KB
testcase_02 AC 121 ms
77,292 KB
testcase_03 AC 91 ms
71,628 KB
testcase_04 AC 173 ms
82,308 KB
testcase_05 AC 189 ms
84,376 KB
testcase_06 AC 122 ms
77,684 KB
testcase_07 AC 221 ms
88,304 KB
testcase_08 AC 275 ms
95,244 KB
testcase_09 AC 99 ms
76,672 KB
testcase_10 AC 97 ms
76,584 KB
testcase_11 AC 99 ms
76,960 KB
testcase_12 AC 149 ms
81,488 KB
testcase_13 AC 99 ms
76,776 KB
testcase_14 AC 99 ms
76,568 KB
testcase_15 AC 99 ms
76,652 KB
testcase_16 AC 100 ms
76,632 KB
testcase_17 AC 98 ms
76,728 KB
testcase_18 AC 92 ms
71,544 KB
testcase_19 AC 515 ms
150,704 KB
testcase_20 AC 736 ms
209,456 KB
testcase_21 AC 121 ms
77,552 KB
testcase_22 AC 99 ms
76,688 KB
testcase_23 AC 97 ms
76,728 KB
testcase_24 AC 98 ms
77,020 KB
testcase_25 AC 195 ms
91,200 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