結果

問題 No.421 しろくろチョコレート
ユーザー H3PO4H3PO4
提出日時 2020-09-16 10:04:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,974 ms / 2,000 ms
コード長 957 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 11,888 KB
実行使用メモリ 96,268 KB
最終ジャッジ日時 2023-10-24 15:02:51
合計ジャッジ時間 51,382 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,974 ms
53,808 KB
testcase_01 AC 693 ms
53,892 KB
testcase_02 AC 690 ms
53,840 KB
testcase_03 AC 698 ms
53,832 KB
testcase_04 AC 691 ms
53,840 KB
testcase_05 AC 692 ms
53,824 KB
testcase_06 AC 696 ms
53,828 KB
testcase_07 AC 698 ms
53,860 KB
testcase_08 AC 696 ms
53,836 KB
testcase_09 AC 695 ms
53,828 KB
testcase_10 AC 694 ms
53,824 KB
testcase_11 AC 697 ms
53,864 KB
testcase_12 AC 695 ms
53,820 KB
testcase_13 AC 694 ms
53,820 KB
testcase_14 AC 692 ms
53,824 KB
testcase_15 AC 697 ms
53,296 KB
testcase_16 AC 697 ms
53,952 KB
testcase_17 AC 703 ms
53,952 KB
testcase_18 AC 700 ms
53,960 KB
testcase_19 AC 695 ms
53,296 KB
testcase_20 AC 699 ms
53,916 KB
testcase_21 AC 698 ms
53,928 KB
testcase_22 AC 697 ms
53,868 KB
testcase_23 AC 702 ms
53,296 KB
testcase_24 AC 699 ms
53,480 KB
testcase_25 AC 692 ms
53,820 KB
testcase_26 AC 697 ms
53,596 KB
testcase_27 AC 695 ms
53,820 KB
testcase_28 AC 700 ms
53,896 KB
testcase_29 AC 696 ms
53,916 KB
testcase_30 AC 692 ms
53,896 KB
testcase_31 AC 705 ms
54,068 KB
testcase_32 AC 697 ms
53,904 KB
testcase_33 AC 697 ms
53,900 KB
testcase_34 AC 698 ms
53,836 KB
testcase_35 AC 699 ms
53,836 KB
testcase_36 AC 697 ms
53,868 KB
testcase_37 AC 698 ms
53,956 KB
testcase_38 AC 703 ms
53,988 KB
testcase_39 AC 699 ms
53,856 KB
testcase_40 AC 699 ms
53,896 KB
testcase_41 AC 696 ms
53,828 KB
testcase_42 AC 693 ms
53,828 KB
testcase_43 AC 701 ms
53,864 KB
testcase_44 AC 703 ms
53,944 KB
testcase_45 AC 699 ms
53,836 KB
testcase_46 AC 702 ms
53,836 KB
testcase_47 AC 696 ms
53,884 KB
testcase_48 AC 701 ms
54,000 KB
testcase_49 AC 696 ms
53,848 KB
testcase_50 AC 698 ms
53,840 KB
testcase_51 AC 701 ms
53,936 KB
testcase_52 AC 695 ms
53,864 KB
testcase_53 AC 692 ms
53,836 KB
testcase_54 AC 695 ms
53,836 KB
testcase_55 AC 694 ms
53,828 KB
testcase_56 AC 695 ms
53,832 KB
testcase_57 AC 696 ms
53,836 KB
testcase_58 AC 696 ms
53,896 KB
testcase_59 AC 698 ms
53,840 KB
testcase_60 AC 700 ms
54,008 KB
testcase_61 AC 706 ms
54,012 KB
testcase_62 AC 696 ms
53,828 KB
testcase_63 AC 692 ms
53,828 KB
testcase_64 AC 695 ms
96,268 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)

size = N * M // 2 + 1
matr = csr_matrix(([1] * len(white), (white, black)), shape=(size, size))
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