結果

問題 No.20 砂漠のオアシス
ユーザー konchanksukonchanksu
提出日時 2020-05-01 00:21:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,456 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 10,364 KB
最終ジャッジ日時 2023-08-22 21:52:35
合計ジャッジ時間 2,319 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,380 KB
testcase_01 WA -
testcase_02 AC 18 ms
8,512 KB
testcase_03 AC 25 ms
8,396 KB
testcase_04 AC 27 ms
8,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 77 ms
9,076 KB
testcase_09 WA -
testcase_10 AC 17 ms
8,464 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
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 -= V - s
heapq.heappush(queue, (s, Oy, Ox))

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

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