結果

問題 No.20 砂漠のオアシス
ユーザー square1001square1001
提出日時 2022-02-17 15:00:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 365 ms / 5,000 ms
コード長 921 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 11,028 KB
最終ジャッジ日時 2023-09-11 17:42:42
合計ジャッジ時間 2,863 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,324 KB
testcase_01 AC 17 ms
8,340 KB
testcase_02 AC 17 ms
8,288 KB
testcase_03 AC 29 ms
8,080 KB
testcase_04 AC 43 ms
8,112 KB
testcase_05 AC 276 ms
11,028 KB
testcase_06 AC 58 ms
9,900 KB
testcase_07 AC 365 ms
10,952 KB
testcase_08 AC 108 ms
9,828 KB
testcase_09 AC 307 ms
10,340 KB
testcase_10 AC 17 ms
8,344 KB
testcase_11 AC 17 ms
8,256 KB
testcase_12 AC 32 ms
8,412 KB
testcase_13 AC 30 ms
8,544 KB
testcase_14 AC 56 ms
8,500 KB
testcase_15 AC 45 ms
8,492 KB
testcase_16 AC 91 ms
8,500 KB
testcase_17 AC 66 ms
8,496 KB
testcase_18 AC 76 ms
8,508 KB
testcase_19 AC 90 ms
8,508 KB
testcase_20 AC 23 ms
8,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

# Input
N, V, OY, OX = map(int, input().split())
L = [ list(map(int, input().split())) for i in range(N) ]
OX, OY = OX - 1, OY - 1

# Dijkstra
dx = [ 0, 1, 0, -1 ]
dy = [ 1, 0, -1, 0 ]
dist = [ [ [ 0 ] * N for j in range(N) ] for i in range(2) ]
vis = [ [ [ False ] * N for j in range(N) ] for i in range(2) ]
que = [ (-V, 0, 0, 0) ]
heapq.heapify(que)
dist[0][0][0] = V
while len(que) >= 1:
	u = heapq.heappop(que)
	if vis[u[1]][u[2]][u[3]]:
		continue
	vis[u[1]][u[2]][u[3]] = True
	for i in range(4):
		tx, ty = u[2] + dx[i], u[3] + dy[i]
		if 0 <= tx and tx < N and 0 <= ty and ty < N:
			ncost = -u[0] - L[tx][ty]
			tc = u[1]
			if tc == 0 and tx == OX and ty == OY:
				ncost *= 2
				tc = 1
			if dist[tc][tx][ty] < ncost:
				dist[tc][tx][ty] = ncost
				heapq.heappush(que, (-ncost, tc, tx, ty))

# Output
if dist[0][N - 1][N - 1] > 0 or dist[1][N - 1][N - 1] > 0:
	print("YES")
else:
	print("NO")
0