結果

問題 No.20 砂漠のオアシス
ユーザー konchanksukonchanksu
提出日時 2020-04-30 21:39:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,447 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 10,192 KB
最終ジャッジ日時 2023-08-22 18:02:41
合計ジャッジ時間 2,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,384 KB
testcase_01 AC 17 ms
8,224 KB
testcase_02 AC 17 ms
8,500 KB
testcase_03 AC 23 ms
8,392 KB
testcase_04 AC 24 ms
8,508 KB
testcase_05 AC 185 ms
10,192 KB
testcase_06 AC 40 ms
9,408 KB
testcase_07 WA -
testcase_08 AC 74 ms
9,116 KB
testcase_09 AC 148 ms
9,580 KB
testcase_10 AC 16 ms
8,436 KB
testcase_11 AC 16 ms
8,212 KB
testcase_12 AC 22 ms
8,220 KB
testcase_13 AC 22 ms
8,268 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 35 ms
8,200 KB
testcase_18 WA -
testcase_19 AC 47 ms
8,564 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

N, V, Ox, Oy = map(int, input().split())
Ox -= 1
Oy -= 1
L = [[int(j) for j in input().split()] for i in range(N)]
already = [[False for i in range(N)] for j in range(N)]
already[0][0] = True

queue = []
heapq.heappush(queue, (L[0][0], 0, 0))

course = [(0, 1), (1, 0), (-1, 0), (0, -1)]
s = 0
while queue:
    tmp = heapq.heappop(queue)
    for i in course:
        y, x = tmp[1] + i[0], tmp[2] + i[1] 
        if x < 0 or y < 0 or x >= N or y >= N:
            continue
        if already[y][x]:
            continue

        if (v := tmp[0] + L[y][x]) >= V:
            continue

        already[y][x] = True
        heapq.heappush(queue, (v, y, x))
        if y == Oy and x == Ox:
            s = v

if already[N - 1][N - 1]:
    print('YES')
    exit()

if (Ox == -1 and Oy == -1) or not already[Oy][Ox]:
    print('NO')
    exit()

already = [[False for i in range(N)] for j in range(N)]
already[0][0] = True
already[Oy][Ox] = True

s -= max(V - s, 0)
heapq.heappush(queue, (s, 0, 0))

while queue:
    tmp = heapq.heappop(queue)
    for i in course:
        y, x = tmp[1] + i[0], tmp[2] + i[1] 
        if x < 0 or y < 0 or x >= N or y >= N:
            continue
        if already[y][x]:
            continue
        
        if (v := tmp[0] + L[y][x]) >= V:
            continue
        
        already[y][x] = True
        heapq.heappush(queue, (v, y, x))

if already[N - 1][N - 1]:
    print('YES')
else:
    print('NO')
0