結果

問題 No.20 砂漠のオアシス
ユーザー terrafarmterrafarm
提出日時 2021-02-14 16:42:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 520 ms / 5,000 ms
コード長 1,354 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 100,540 KB
最終ジャッジ日時 2023-09-29 07:32:59
合計ジャッジ時間 9,205 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 276 ms
92,916 KB
testcase_01 AC 299 ms
93,088 KB
testcase_02 AC 269 ms
92,988 KB
testcase_03 AC 312 ms
95,964 KB
testcase_04 AC 331 ms
96,204 KB
testcase_05 AC 520 ms
100,540 KB
testcase_06 AC 463 ms
100,200 KB
testcase_07 AC 455 ms
100,020 KB
testcase_08 AC 464 ms
98,716 KB
testcase_09 AC 467 ms
100,212 KB
testcase_10 AC 269 ms
92,964 KB
testcase_11 AC 271 ms
93,112 KB
testcase_12 AC 333 ms
96,596 KB
testcase_13 AC 336 ms
95,856 KB
testcase_14 AC 346 ms
95,688 KB
testcase_15 AC 346 ms
96,144 KB
testcase_16 AC 354 ms
96,112 KB
testcase_17 AC 341 ms
95,872 KB
testcase_18 AC 355 ms
96,416 KB
testcase_19 AC 353 ms
96,092 KB
testcase_20 AC 327 ms
95,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import logging
import sys
from inspect import currentframe

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
logging.basicConfig(level=logging.DEBUG)


def dbg(*args):
    id2names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    logging.debug(", ".join(id2names.get(id(arg), "???") + " = " + repr(arg) for arg in args))


def dijkstra_grid(sx, sy, grid):
    d = [[float('inf')] * n for _ in range(n)]
    d[sx][sy] = 0
    pq = [(0, sx, sy)]
    while pq:
        c, x, y = heapq.heappop(pq)
        if d[x][y] < c:
            continue
        for dx, dy in ((-1, 0), (1, 0), (0, 1), (0, -1)):
            nx, ny = x + dx, y + dy
            if 0 <= nx < n and 0 <= ny < n and c + grid[nx][ny] < d[nx][ny]:
                d[nx][ny] = c + grid[nx][ny]
                heapq.heappush(pq, (d[nx][ny], nx, ny))
    return d


n, v, oy, ox = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
d1 = dijkstra_grid(0, 0, l)
if ox == 0 and oy == 0:
    if d1[n - 1][n - 1] < v:
        print("YES")
    else:
        print("NO")
else:
    ox -= 1
    oy -= 1
    d2 = dijkstra_grid(ox, oy, l)
    dbg(d1)
    dbg(d2)
    if d1[n - 1][n - 1] < v:
        print("YES")
    elif d1[ox][oy] < v and d2[n - 1][n - 1] < 2 * (v - d1[ox][oy]):
        print("YES")
    else:
        print("NO")
0