結果

問題 No.20 砂漠のオアシス
ユーザー H3PO4H3PO4
提出日時 2020-04-19 00:35:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,245 ms / 5,000 ms
コード長 842 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 74,148 KB
最終ジャッジ日時 2024-04-14 21:22:04
合計ジャッジ時間 26,653 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 924 ms
56,168 KB
testcase_01 AC 929 ms
56,304 KB
testcase_02 AC 930 ms
56,168 KB
testcase_03 AC 950 ms
56,692 KB
testcase_04 AC 942 ms
56,936 KB
testcase_05 AC 1,177 ms
69,500 KB
testcase_06 AC 1,245 ms
73,900 KB
testcase_07 AC 1,234 ms
74,020 KB
testcase_08 AC 1,226 ms
73,920 KB
testcase_09 AC 1,240 ms
74,148 KB
testcase_10 AC 926 ms
56,560 KB
testcase_11 AC 925 ms
56,300 KB
testcase_12 AC 947 ms
56,436 KB
testcase_13 AC 950 ms
56,684 KB
testcase_14 AC 970 ms
57,068 KB
testcase_15 AC 938 ms
56,816 KB
testcase_16 AC 982 ms
57,316 KB
testcase_17 AC 978 ms
56,556 KB
testcase_18 AC 984 ms
57,704 KB
testcase_19 AC 978 ms
57,468 KB
testcase_20 AC 934 ms
56,312 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