結果

問題 No.421 しろくろチョコレート
ユーザー masa_aamasa_aa
提出日時 2021-05-21 00:49:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,168 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 74,852 KB
最終ジャッジ日時 2024-04-18 14:11:59
合計ジャッジ時間 5,265 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,736 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 55 ms
61,696 KB
testcase_08 WA -
testcase_09 AC 43 ms
53,120 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 37 ms
52,224 KB
testcase_13 AC 35 ms
52,352 KB
testcase_14 AC 39 ms
52,480 KB
testcase_15 AC 39 ms
52,736 KB
testcase_16 WA -
testcase_17 AC 78 ms
72,980 KB
testcase_18 AC 73 ms
72,960 KB
testcase_19 AC 40 ms
52,096 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 39 ms
52,608 KB
testcase_24 AC 37 ms
52,480 KB
testcase_25 AC 38 ms
52,480 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 50 ms
63,360 KB
testcase_29 AC 59 ms
66,944 KB
testcase_30 AC 59 ms
66,304 KB
testcase_31 AC 58 ms
66,304 KB
testcase_32 WA -
testcase_33 AC 62 ms
66,816 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 64 ms
72,320 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 41 ms
53,376 KB
testcase_42 AC 40 ms
53,376 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 61 ms
71,040 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 67 ms
73,088 KB
testcase_52 AC 53 ms
62,592 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 78 ms
74,852 KB
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 AC 44 ms
59,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BipartiteMatching:
    def __init__(self, N, M):
        self.N = N
        self.M = M
        self.pairA = [-1] * N
        self.pairB = [-1] * M
        self.edge = [[] for _ in range(N)]
        self.was = [0] * N
        self.iter = 0

    def add_edge(self, s, t):
        self.edge[s].append(t)

    def _DFS(self, s):
        self.was[s] = self.iter
        for t in self.edge[s]:
            if self.pairB[t] == -1:
                self.pairA[s] = t
                self.pairB[t] = s
                return True
        for t in self.edge[s]:
            if self.was[self.pairB[t]] != self.iter and self._DFS(self.pairB[t]):
                self.pairA[s] = t
                self.pairB[t] = s
                return True
        return False

    def bipartite_matching(self):
        res = 0
        while True:
            self.iter += 1
            found = 0
            for i in range(self.N):
                if self.pairA[i] == -1 and self._DFS(i):
                    found += 1
            if not found:
                break
            res += found
        return res


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)

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