結果

問題 No.697 池の数はいくつか
ユーザー H3PO4H3PO4
提出日時 2020-12-06 21:28:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 896 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 11,056 KB
実行使用メモリ 814,016 KB
最終ジャッジ日時 2023-08-16 23:51:03
合計ジャッジ時間 19,225 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 220 ms
43,056 KB
testcase_01 AC 230 ms
43,112 KB
testcase_02 AC 204 ms
43,072 KB
testcase_03 AC 205 ms
42,948 KB
testcase_04 AC 206 ms
43,052 KB
testcase_05 AC 205 ms
43,296 KB
testcase_06 AC 226 ms
43,092 KB
testcase_07 AC 220 ms
43,204 KB
testcase_08 AC 218 ms
42,724 KB
testcase_09 AC 219 ms
42,740 KB
testcase_10 AC 212 ms
43,060 KB
testcase_11 AC 209 ms
43,072 KB
testcase_12 AC 205 ms
42,736 KB
testcase_13 AC 206 ms
43,340 KB
testcase_14 AC 207 ms
43,028 KB
testcase_15 AC 204 ms
43,024 KB
testcase_16 AC 204 ms
42,612 KB
testcase_17 AC 203 ms
43,032 KB
testcase_18 AC 204 ms
43,028 KB
testcase_19 AC 202 ms
43,076 KB
testcase_20 AC 204 ms
42,928 KB
testcase_21 AC 200 ms
43,248 KB
testcase_22 AC 200 ms
42,560 KB
testcase_23 AC 202 ms
43,168 KB
testcase_24 AC 573 ms
96,556 KB
testcase_25 AC 571 ms
96,720 KB
testcase_26 AC 567 ms
96,752 KB
testcase_27 AC 575 ms
96,520 KB
testcase_28 AC 576 ms
96,740 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

input = sys.stdin.buffer.readline


def main():
    H, W = map(int, input().split())
    A = np.array([tuple(map(int, input().split())) for _ in range(H)], dtype=bool)
    F = np.arange(H * W).reshape((H, W))

    HC = A[1:] & A[:-1]
    WC = A[:, 1:] & A[:, :-1]
    ZW = np.zeros(W, dtype=bool).reshape(1, W)
    ZH = np.zeros(H, dtype=bool).reshape(H, 1)
    frm = np.hstack((F[np.concatenate([ZW, HC], 0)],
                     F[np.concatenate([ZH, WC], 1)]))
    to = np.hstack((F[np.concatenate([HC, ZW], 0)],
                    F[np.concatenate([WC, ZH], 1)]))
    L = len(frm)
    matr = csr_matrix(([1] * L, (frm, to)), shape=(H * W, H * W))
    p = connected_components(matr, return_labels=False)
    ans = p - np.count_nonzero(~A)
    return ans


print(main())
0