結果

問題 No.20 砂漠のオアシス
ユーザー square1001square1001
提出日時 2022-02-17 14:59:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 921 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 10,984 KB
最終ジャッジ日時 2023-09-11 17:42:39
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,272 KB
testcase_01 AC 17 ms
8,344 KB
testcase_02 AC 17 ms
8,148 KB
testcase_03 AC 30 ms
8,124 KB
testcase_04 AC 43 ms
8,128 KB
testcase_05 AC 275 ms
10,984 KB
testcase_06 AC 55 ms
9,828 KB
testcase_07 AC 350 ms
10,956 KB
testcase_08 AC 108 ms
9,888 KB
testcase_09 AC 283 ms
10,452 KB
testcase_10 WA -
testcase_11 AC 16 ms
8,300 KB
testcase_12 WA -
testcase_13 AC 29 ms
8,536 KB
testcase_14 AC 53 ms
8,496 KB
testcase_15 AC 44 ms
8,396 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 90 ms
8,580 KB
testcase_20 AC 26 ms
8,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

# Input
N, V, OX, OY = 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