結果
問題 |
No.421 しろくろチョコレート
|
ユーザー |
|
提出日時 | 2020-09-16 10:04:28 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 957 bytes |
コンパイル時間 | 384 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 73,336 KB |
最終ジャッジ日時 | 2025-03-17 11:48:39 |
合計ジャッジ時間 | 7,285 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 64 |
ソースコード
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)