結果
| 問題 |
No.421 しろくろチョコレート
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-16 10:01:13 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 947 bytes |
| コンパイル時間 | 128 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 57,200 KB |
| 最終ジャッジ日時 | 2024-06-22 03:07:25 |
| 合計ジャッジ時間 | 70,000 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 57 RE * 8 |
ソースコード
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)