結果
問題 | No.20 砂漠のオアシス |
ユーザー |
![]() |
提出日時 | 2022-02-17 14:59:14 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 921 bytes |
コンパイル時間 | 88 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 13,696 KB |
最終ジャッジ日時 | 2024-06-29 07:41:22 |
合計ジャッジ時間 | 3,042 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 WA * 5 |
ソースコード
import heapq# InputN, V, OX, OY = map(int, input().split())L = [ list(map(int, input().split())) for i in range(N) ]OX, OY = OX - 1, OY - 1# Dijkstradx = [ 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] = Vwhile len(que) >= 1:u = heapq.heappop(que)if vis[u[1]][u[2]][u[3]]:continuevis[u[1]][u[2]][u[3]] = Truefor 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 *= 2tc = 1if dist[tc][tx][ty] < ncost:dist[tc][tx][ty] = ncostheapq.heappush(que, (-ncost, tc, tx, ty))# Outputif dist[0][N - 1][N - 1] > 0 or dist[1][N - 1][N - 1] > 0:print("YES")else:print("NO")