結果
問題 | No.20 砂漠のオアシス |
ユーザー | sotanishy |
提出日時 | 2021-03-16 22:53:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 301 ms / 5,000 ms |
コード長 | 911 bytes |
コンパイル時間 | 199 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 80,896 KB |
最終ジャッジ日時 | 2024-11-08 18:41:12 |
合計ジャッジ時間 | 3,882 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
from heapq import heappush, heappopimport sysinput = sys.stdin.readlinedef dijkstra(si, sj):INF = 10**18dist = [[INF] * N for _ in range(N)]dist[si][sj] = 0pq = [(0, si, sj)]while pq:d, i, j = heappop(pq)if dist[i][j] < d:continuefor di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:ni, nj = i + di, j + djif 0 <= ni < N and 0 <= nj < N and dist[ni][nj] > d + L[ni][nj]:dist[ni][nj] = d + L[ni][nj]heappush(pq, (d + L[ni][nj], ni, nj))return distN, V, Ox, Oy = map(int, input().split())Ox -= 1Oy -= 1L = [list(map(int, input().split())) for _ in range(N)]dist0 = dijkstra(0, 0)if Ox == Oy == -1:print('YES' if dist0[N-1][N-1] < V else 'NO')exit()dist1 = dijkstra(Oy, Ox)print('YES' if dist0[N-1][N-1] < V or (V - dist0[Oy][Ox]) * 2 > dist1[N-1][N-1] else 'NO')