結果
問題 | No.20 砂漠のオアシス |
ユーザー | Kude |
提出日時 | 2020-09-04 04:39:55 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 948 bytes |
コンパイル時間 | 1,803 ms |
コンパイル使用メモリ | 86,988 KB |
実行使用メモリ | 79,132 KB |
最終ジャッジ日時 | 2023-08-16 06:26:39 |
合計ジャッジ時間 | 10,293 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,616 KB |
testcase_01 | AC | 124 ms
77,268 KB |
testcase_02 | AC | 90 ms
76,672 KB |
testcase_03 | AC | 471 ms
77,688 KB |
testcase_04 | AC | 2,169 ms
79,132 KB |
testcase_05 | TLE | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
ソースコード
n, v, ox, oy = map(int, input().split()) ox -= 1 oy -= 1 l = [list(map(int, input().split())) for _ in range(n)] INF = 10 ** 18 from heapq import heappush, heappop dx = [1,0,-1,0] dy = [0,1,0,-1] def min_cost(sx, sy, gx, gy): dp = [[INF] * n for _ in range(n)] dp[sx][sy] = 0 q = [(0, sx, sy)] while q: cost, x, y = q.pop() if cost > dp[x][y]: continue for k in range(4): nx = x + dx[k] ny = y + dy[k] if not (0 <= nx < n and 0 <= ny < n): continue nc = cost + l[nx][ny] if nc < dp[nx][ny]: dp[nx][ny] = nc heappush(q, (nc, nx, ny)) return dp[gx][gy] ok = False if min_cost(0, 0, n-1, n-1) < v: ok = True if ox >= 0: nv = v - min_cost(0, 0, ox, oy) if nv >= 1: nv *= 2 if min_cost(ox, oy, n-1, n-1) < nv: ok = True print('YES' if ok else 'NO')