結果

問題 No.20 砂漠のオアシス
ユーザー nisizawanisizawa
提出日時 2017-12-10 10:09:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 1,121 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 10,516 KB
最終ジャッジ日時 2023-08-20 09:49:38
合計ジャッジ時間 2,315 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,064 KB
testcase_01 AC 17 ms
8,212 KB
testcase_02 AC 17 ms
8,108 KB
testcase_03 AC 22 ms
8,144 KB
testcase_04 AC 22 ms
8,188 KB
testcase_05 AC 118 ms
10,504 KB
testcase_06 AC 36 ms
9,196 KB
testcase_07 AC 142 ms
10,516 KB
testcase_08 AC 54 ms
9,364 KB
testcase_09 AC 120 ms
9,856 KB
testcase_10 AC 17 ms
8,132 KB
testcase_11 AC 17 ms
8,124 KB
testcase_12 AC 22 ms
8,124 KB
testcase_13 AC 22 ms
8,236 KB
testcase_14 AC 29 ms
8,236 KB
testcase_15 AC 27 ms
8,216 KB
testcase_16 AC 42 ms
8,576 KB
testcase_17 AC 33 ms
8,136 KB
testcase_18 AC 36 ms
8,468 KB
testcase_19 AC 41 ms
8,532 KB
testcase_20 AC 20 ms
8,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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')
0