結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 818 ms
56,176 KB
testcase_01 AC 816 ms
56,052 KB
testcase_02 AC 815 ms
56,040 KB
testcase_03 AC 823 ms
56,564 KB
testcase_04 AC 822 ms
56,688 KB
testcase_05 AC 1,041 ms
69,412 KB
testcase_06 AC 1,080 ms
73,012 KB
testcase_07 AC 1,096 ms
73,324 KB
testcase_08 AC 1,082 ms
73,588 KB
testcase_09 AC 1,087 ms
73,072 KB
testcase_10 AC 808 ms
56,304 KB
testcase_11 AC 818 ms
56,048 KB
testcase_12 AC 828 ms
56,568 KB
testcase_13 AC 835 ms
56,696 KB
testcase_14 AC 842 ms
57,320 KB
testcase_15 AC 832 ms
56,820 KB
testcase_16 AC 871 ms
57,328 KB
testcase_17 AC 847 ms
57,336 KB
testcase_18 AC 876 ms
57,084 KB
testcase_19 AC 876 ms
57,712 KB
testcase_20 AC 817 ms
56,296 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