結果

問題 No.20 砂漠のオアシス
ユーザー konchanksukonchanksu
提出日時 2020-04-30 21:34:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,440 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 81,196 KB
最終ジャッジ日時 2023-08-22 17:54:42
合計ジャッジ時間 4,962 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,124 KB
testcase_01 AC 79 ms
71,184 KB
testcase_02 AC 79 ms
70,860 KB
testcase_03 AC 128 ms
78,104 KB
testcase_04 AC 146 ms
78,496 KB
testcase_05 AC 284 ms
81,196 KB
testcase_06 AC 176 ms
79,304 KB
testcase_07 WA -
testcase_08 AC 158 ms
78,448 KB
testcase_09 AC 245 ms
79,848 KB
testcase_10 WA -
testcase_11 AC 76 ms
71,308 KB
testcase_12 AC 146 ms
78,252 KB
testcase_13 AC 129 ms
77,720 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 189 ms
79,248 KB
testcase_18 WA -
testcase_19 AC 186 ms
79,404 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, (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