結果

問題 No.20 砂漠のオアシス
ユーザー H3PO4H3PO4
提出日時 2020-04-19 00:35:33
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 438 ms / 5,000 ms
コード長 842 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 63,364 KB
最終ジャッジ日時 2023-07-27 08:33:37
合計ジャッジ時間 9,839 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 211 ms
42,996 KB
testcase_01 AC 217 ms
43,112 KB
testcase_02 AC 215 ms
43,060 KB
testcase_03 AC 221 ms
43,868 KB
testcase_04 AC 220 ms
43,780 KB
testcase_05 AC 384 ms
59,160 KB
testcase_06 AC 438 ms
63,364 KB
testcase_07 AC 438 ms
63,300 KB
testcase_08 AC 416 ms
63,324 KB
testcase_09 AC 431 ms
63,344 KB
testcase_10 AC 219 ms
43,016 KB
testcase_11 AC 210 ms
43,036 KB
testcase_12 AC 225 ms
43,884 KB
testcase_13 AC 223 ms
44,136 KB
testcase_14 AC 233 ms
44,572 KB
testcase_15 AC 225 ms
44,148 KB
testcase_16 AC 252 ms
46,816 KB
testcase_17 AC 249 ms
45,516 KB
testcase_18 AC 252 ms
46,148 KB
testcase_19 AC 255 ms
46,812 KB
testcase_20 AC 218 ms
43,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

N, V, Ox, Oy = map(int, input().split())
L = [tuple(map(int, input().split())) for _ in range(N)]

data, row, col = [], [], []
for y in range(N):
    for x in range(N):
        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            if 0 <= x + dx < N and 0 <= y + dy < N:
                data.append(L[y][x])
                row.append((y + dy) * N + x + dx)
                col.append(y * N + x)

matr = csr_matrix((data, (row, col)), shape=(N * N, N * N))
way = dijkstra(matr, indices=0).astype(int)

flag = way[N * N - 1] < V
if (Ox, Oy) != (0, 0):
    oasis = (Oy - 1) * N + Ox - 1
    lo = way[oasis]
    if lo < V:
        wayo = dijkstra(matr, indices=oasis).astype(int)
        flag |= wayo[N * N - 1] < (V - lo) * 2
print('YES' if flag else 'NO')
0