結果
問題 | No.421 しろくろチョコレート |
ユーザー |
![]() |
提出日時 | 2021-07-14 21:59:28 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 1,456 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-09-23 07:31:59 |
合計ジャッジ時間 | 4,158 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 65 |
ソースコード
import collectionsimport syssys.setrecursionlimit(10 ** 6)input = sys.stdin.readlinedef dfs(v, left, right, used, g):if v in used: return Falseused.add(v)for u in g[v]:if right[u] == -1 or dfs(right[u], left, right, used, g):right[u] = vleft[v] = ureturn Truereturn Falsedef max_bipartite_matching(n, m, g):res = 0left = [-1] * nright = [-1] * mused = set()update = Truewhile update:update = Falsefor i in range(len(left)):if left[i] == -1 and dfs(i, left, right, used, g):update = Trueres += 1if update:used = set()return res, left, rightN, M = map(int, input().split())g = [input() for _ in range(N)]w = b = 0adj = collections.defaultdict(list)for i in range(N):for j in range(M):if g[i][j] == 'w': w += 1if g[i][j] == 'b': b += 1if (i + j) % 2 == 1: continuefor dr, dc in [(1, 0), (-1, 0), (0, 1), (0, -1)]:r = i + drc = j + dcif 0 <= r < N and 0 <= c < M:if sorted([g[i][j], g[r][c]]) == ['b', 'w']:p = i * M + jq = r * M + cadj[p].append(q)cnt, _, _ = max_bipartite_matching(N * M, N * M, adj)w -= cntb -= cntk = min(w, b)ans = cnt * 100 + k * 10 + (w - k) + (b - k)print(ans)