結果

問題 No.421 しろくろチョコレート
ユーザー masa_aamasa_aa
提出日時 2021-05-21 00:45:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,837 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 81,920 KB
最終ジャッジ日時 2024-04-18 14:11:45
合計ジャッジ時間 7,854 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,608 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 94 ms
76,032 KB
testcase_08 WA -
testcase_09 AC 61 ms
64,768 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 41 ms
52,352 KB
testcase_13 AC 41 ms
52,608 KB
testcase_14 AC 41 ms
52,352 KB
testcase_15 AC 41 ms
51,968 KB
testcase_16 WA -
testcase_17 AC 140 ms
77,312 KB
testcase_18 AC 172 ms
77,788 KB
testcase_19 AC 41 ms
52,224 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 41 ms
52,224 KB
testcase_24 AC 41 ms
52,352 KB
testcase_25 AC 40 ms
52,480 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 107 ms
77,568 KB
testcase_29 AC 115 ms
76,416 KB
testcase_30 AC 117 ms
77,056 KB
testcase_31 AC 363 ms
81,920 KB
testcase_32 WA -
testcase_33 AC 127 ms
77,952 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 194 ms
77,312 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 93 ms
75,648 KB
testcase_42 AC 67 ms
68,096 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 237 ms
79,740 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 189 ms
77,500 KB
testcase_52 AC 96 ms
76,160 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 205 ms
77,952 KB
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 AC 70 ms
75,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BipartiteMatching:
    def __init__(self, n, m):
        self.size = n + m
        self._n = n
        self._g = [[] for _ in range(n)]
        self.matchA = [-1] * n
        self.matchB = [-1] * m

    def add_edge(self, u, v):
        self._g[u].append(v)

    def dfs(self, v):
        self.used[v] = True
        for u in self._g[v]:
            w = self.matchB[u]
            if w < 0 or not self.used[w] and self.dfs(w):
                self.matchA[v] = u
                self.matchB[u] = v
                return True
        return False

    def bipartite_matching(self):
        res = 0
        for v in range(self._n):
            if self.matchA[v] < 0:
                self.used = [0] * self._n
                if self.dfs(v):
                    res += 1
        return res


import sys
input = sys.stdin.readline

n, m = map(int, input().split())
s = [input() for _ in range(n)]
bm = BipartiteMatching(n * m // 2 + 1, n * m // 2)
b, w = 0, 0
for i in range(n):
    for j in range(m):
        if s[i][j] == ".":
            continue
        if s[i][j] == "b":
            b += 1
        else:
            w += 1

        if (i + j) % 2:
            if j < m - 1:
                if s[i][j + 1] != ".":
                    bm.add_edge((i * m + j + 1) // 2, (i * m + j) // 2)
            if i < n - 1:
                if s[i + 1][j] != ".":
                    bm.add_edge(((i + 1) * m + j) // 2, (i * m + j) // 2)
        else:
            if j < m - 1:
                if s[i][j + 1] != ".":
                    bm.add_edge((i * m + j) // 2, (i * m + j + 1) // 2)
            if i < n - 1:
                if s[i + 1][j] != ".":
                    bm.add_edge((i * m + j) // 2, ((i + 1) * m + j) // 2)

match = bm.bipartite_matching()
b -= match
w -= match
k = min(b, m)
print(100 * match + 10 * k + (b + w - k - k))
0