結果
問題 | No.421 しろくろチョコレート |
ユーザー |
|
提出日時 | 2020-09-16 10:04:28 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,428 ms / 2,000 ms |
コード長 | 957 bytes |
コンパイル時間 | 80 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 110,704 KB |
最終ジャッジ日時 | 2024-09-23 07:28:35 |
合計ジャッジ時間 | 66,458 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
外部呼び出し有り |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 65 |
ソースコード
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)