結果

問題 No.20 砂漠のオアシス
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-24 04:20:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 251 ms / 5,000 ms
コード長 1,060 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,812 KB
実行使用メモリ 79,328 KB
最終ジャッジ日時 2023-10-21 15:33:20
合計ジャッジ時間 3,426 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,472 KB
testcase_01 AC 39 ms
53,472 KB
testcase_02 AC 39 ms
53,472 KB
testcase_03 AC 87 ms
76,408 KB
testcase_04 AC 96 ms
76,512 KB
testcase_05 AC 251 ms
79,328 KB
testcase_06 AC 98 ms
77,552 KB
testcase_07 AC 165 ms
77,792 KB
testcase_08 AC 123 ms
77,700 KB
testcase_09 AC 160 ms
77,716 KB
testcase_10 AC 40 ms
53,504 KB
testcase_11 AC 39 ms
53,504 KB
testcase_12 AC 83 ms
74,440 KB
testcase_13 AC 89 ms
76,428 KB
testcase_14 AC 105 ms
76,596 KB
testcase_15 AC 94 ms
76,512 KB
testcase_16 AC 110 ms
76,800 KB
testcase_17 AC 104 ms
76,636 KB
testcase_18 AC 106 ms
76,772 KB
testcase_19 AC 107 ms
76,716 KB
testcase_20 AC 76 ms
73,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10000
DX = (-1, 0, 1, 0, -1, -1, 1, 1)
DY = (0, 1, 0, -1, -1, 1, -1, 1)
DX = DX[:4]
DY = DY[:4]

N, V, oy, ox = map(int, input().split())
L = tuple(tuple(map(int, input().split())) for _ in range(N))
ox -= 1
oy -= 1

dist = [[inf] * N for _ in range(N)]
dist[0][0] = 0
que = [(0, 0, 0)]
while que:
    ds, x, y = heapq.heappop(que)
    if dist[x][y] < ds:
        continue
    for dx, dy in zip(DX, DY):
        nx = x + dx
        ny = y + dy
        if nx < 0 or N <= nx or ny < 0 or N <= ny:
            continue
        cost = ds + L[nx][ny]
        if cost >= V:
            continue
        if dist[nx][ny] > cost:
            dist[nx][ny] = cost
            if (nx, ny) == (ox, oy):
                dist[nx][ny] -= (V - cost)
                ox = -1
                oy = -1
            heapq.heappush(que, (dist[nx][ny], nx, ny))

# if 1:
#     import numpy as np
#     print(np.array(dist))

if dist[N - 1][N - 1] < V:
    print("YES")
else:
    print("NO")
0