結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,380 KB
testcase_01 AC 17 ms
8,152 KB
testcase_02 AC 17 ms
8,448 KB
testcase_03 AC 25 ms
8,352 KB
testcase_04 AC 26 ms
8,284 KB
testcase_05 AC 193 ms
10,156 KB
testcase_06 AC 47 ms
9,364 KB
testcase_07 AC 225 ms
9,380 KB
testcase_08 AC 76 ms
8,984 KB
testcase_09 AC 197 ms
9,312 KB
testcase_10 AC 17 ms
8,460 KB
testcase_11 WA -
testcase_12 AC 26 ms
8,052 KB
testcase_13 AC 25 ms
8,060 KB
testcase_14 AC 40 ms
8,264 KB
testcase_15 AC 34 ms
8,136 KB
testcase_16 AC 64 ms
8,552 KB
testcase_17 AC 47 ms
8,056 KB
testcase_18 WA -
testcase_19 AC 61 ms
8,480 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 -= 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))


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