結果

問題 No.421 しろくろチョコレート
ユーザー H3PO4H3PO4
提出日時 2020-09-16 10:01:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 947 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 73,940 KB
最終ジャッジ日時 2023-09-04 03:24:49
合計ジャッジ時間 21,390 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 611 ms
43,260 KB
testcase_01 AC 225 ms
43,372 KB
testcase_02 AC 223 ms
43,240 KB
testcase_03 AC 218 ms
43,300 KB
testcase_04 AC 223 ms
43,312 KB
testcase_05 AC 221 ms
43,424 KB
testcase_06 AC 218 ms
43,336 KB
testcase_07 AC 224 ms
43,432 KB
testcase_08 RE -
testcase_09 AC 218 ms
43,316 KB
testcase_10 AC 217 ms
43,228 KB
testcase_11 AC 222 ms
43,512 KB
testcase_12 AC 218 ms
43,328 KB
testcase_13 AC 216 ms
43,256 KB
testcase_14 AC 220 ms
43,288 KB
testcase_15 AC 221 ms
42,680 KB
testcase_16 AC 224 ms
43,544 KB
testcase_17 AC 220 ms
43,532 KB
testcase_18 AC 219 ms
43,560 KB
testcase_19 AC 219 ms
42,568 KB
testcase_20 AC 224 ms
43,464 KB
testcase_21 AC 223 ms
43,508 KB
testcase_22 AC 225 ms
43,432 KB
testcase_23 AC 224 ms
42,580 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 226 ms
43,444 KB
testcase_29 AC 220 ms
43,348 KB
testcase_30 AC 215 ms
43,464 KB
testcase_31 AC 226 ms
43,776 KB
testcase_32 AC 225 ms
43,372 KB
testcase_33 AC 217 ms
43,416 KB
testcase_34 AC 213 ms
43,352 KB
testcase_35 AC 214 ms
43,324 KB
testcase_36 RE -
testcase_37 AC 223 ms
43,640 KB
testcase_38 AC 227 ms
43,728 KB
testcase_39 AC 225 ms
43,504 KB
testcase_40 AC 222 ms
43,508 KB
testcase_41 AC 219 ms
43,244 KB
testcase_42 AC 225 ms
43,216 KB
testcase_43 AC 223 ms
43,504 KB
testcase_44 AC 227 ms
43,664 KB
testcase_45 AC 219 ms
43,432 KB
testcase_46 AC 216 ms
43,348 KB
testcase_47 RE -
testcase_48 AC 240 ms
43,804 KB
testcase_49 AC 222 ms
43,352 KB
testcase_50 RE -
testcase_51 AC 228 ms
43,564 KB
testcase_52 AC 230 ms
43,456 KB
testcase_53 AC 225 ms
43,280 KB
testcase_54 AC 224 ms
43,348 KB
testcase_55 AC 226 ms
43,516 KB
testcase_56 AC 219 ms
43,296 KB
testcase_57 AC 220 ms
43,272 KB
testcase_58 AC 218 ms
43,672 KB
testcase_59 AC 221 ms
43,328 KB
testcase_60 AC 229 ms
43,732 KB
testcase_61 AC 225 ms
43,912 KB
testcase_62 AC 218 ms
43,208 KB
testcase_63 AC 219 ms
43,344 KB
testcase_64 AC 222 ms
73,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import maximum_bipartite_matching

N, M = map(int, input().split())
S = [input() for _ in range(N)]


def idx2int(n, m):
    return (n * M + m) // 2


white, black = [], []
for x in range(N):
    for y in range(x % 2, M, 2):
        if S[x][y] == 'w':
            for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
                if 0 <= x + dx < N and 0 <= y + dy < M and S[x + dx][y + dy] == 'b':
                    white.append(idx2int(x, y))
                    black.append(idx2int(x + dx, y + dy))
w_count = sum(s.count('w') for s in S)
b_count = sum(s.count('b') for s in S)

matr = csr_matrix(([1] * len(white), (white, black)), shape=(N * M // 2, N * M // 2))
match = sum(maximum_bipartite_matching(matr, perm_type='column') != -1)

w_count -= match
b_count -= match
major, minor = max(w_count, b_count), min(w_count, b_count)
print(match * 100 + minor * 10 + major - minor)
0