結果
問題 | No.20 砂漠のオアシス |
ユーザー | nisizawa |
提出日時 | 2017-12-10 10:09:51 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 177 ms / 5,000 ms |
コード長 | 1,121 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 13,056 KB |
最終ジャッジ日時 | 2024-11-30 11:14:29 |
合計ジャッジ時間 | 2,295 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
from heapq import heapify, heappop, heappush def v_map(n, v, sx, sy, map_dmg): memo_v = [[0] * n for i in range(n)] hq = [(-v, v, sx, sy)] while len(hq) > 0: (t, v, x, y) = heappop(hq) memo_v[y][x] = v if x == n - 1 and y == n - 1: break next_ls = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)] for (new_x, new_y) in next_ls: if not (0 <= new_x < n and 0 <= new_y < n): continue new_v = v - map_dmg[new_y][new_x] if memo_v[new_y][new_x] >= new_v: continue memo_v[new_y][new_x] = new_v heappush(hq, (-new_v, new_v, new_x, new_y)) return memo_v n, v, ox, oy = map(int, input().split()) map_dmg = [] for i in range(n): map_dmg.append(list(map(int, input().split()))) memo_v = v_map(n, v, 0, 0, map_dmg) if not (memo_v[n - 1][n - 1] > 0 or (ox == 0 and oy == 0)): v = memo_v[oy - 1][ox - 1] * 2 memo_v = v_map(n, v, ox - 1, oy - 1, map_dmg) if memo_v[n - 1][n - 1] > 0: print('YES') else: print('NO')