結果
問題 | No.421 しろくろチョコレート |
ユーザー | rlangevin |
提出日時 | 2023-07-20 12:24:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 174 ms / 2,000 ms |
コード長 | 2,388 bytes |
コンパイル時間 | 211 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 80,112 KB |
最終ジャッジ日時 | 2024-09-20 08:56:48 |
合計ジャッジ時間 | 7,991 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,656 KB |
testcase_01 | AC | 136 ms
78,828 KB |
testcase_02 | AC | 66 ms
69,504 KB |
testcase_03 | AC | 52 ms
62,464 KB |
testcase_04 | AC | 61 ms
66,560 KB |
testcase_05 | AC | 72 ms
72,192 KB |
testcase_06 | AC | 53 ms
60,544 KB |
testcase_07 | AC | 107 ms
77,376 KB |
testcase_08 | AC | 70 ms
68,224 KB |
testcase_09 | AC | 74 ms
69,888 KB |
testcase_10 | AC | 67 ms
69,888 KB |
testcase_11 | AC | 111 ms
77,616 KB |
testcase_12 | AC | 41 ms
54,144 KB |
testcase_13 | AC | 43 ms
54,272 KB |
testcase_14 | AC | 43 ms
54,016 KB |
testcase_15 | AC | 42 ms
54,272 KB |
testcase_16 | AC | 141 ms
79,048 KB |
testcase_17 | AC | 144 ms
79,324 KB |
testcase_18 | AC | 140 ms
79,160 KB |
testcase_19 | AC | 44 ms
54,144 KB |
testcase_20 | AC | 127 ms
78,800 KB |
testcase_21 | AC | 149 ms
78,968 KB |
testcase_22 | AC | 122 ms
78,004 KB |
testcase_23 | AC | 47 ms
54,400 KB |
testcase_24 | AC | 42 ms
54,400 KB |
testcase_25 | AC | 43 ms
54,016 KB |
testcase_26 | AC | 43 ms
54,400 KB |
testcase_27 | AC | 43 ms
54,144 KB |
testcase_28 | AC | 106 ms
77,988 KB |
testcase_29 | AC | 118 ms
78,792 KB |
testcase_30 | AC | 116 ms
78,580 KB |
testcase_31 | AC | 121 ms
79,564 KB |
testcase_32 | AC | 124 ms
79,076 KB |
testcase_33 | AC | 122 ms
78,640 KB |
testcase_34 | AC | 50 ms
61,824 KB |
testcase_35 | AC | 53 ms
64,128 KB |
testcase_36 | AC | 96 ms
77,780 KB |
testcase_37 | AC | 140 ms
79,216 KB |
testcase_38 | AC | 162 ms
79,528 KB |
testcase_39 | AC | 87 ms
77,056 KB |
testcase_40 | AC | 134 ms
78,544 KB |
testcase_41 | AC | 72 ms
72,192 KB |
testcase_42 | AC | 62 ms
66,688 KB |
testcase_43 | AC | 96 ms
77,312 KB |
testcase_44 | AC | 159 ms
79,252 KB |
testcase_45 | AC | 70 ms
70,912 KB |
testcase_46 | AC | 64 ms
67,968 KB |
testcase_47 | AC | 121 ms
78,332 KB |
testcase_48 | AC | 141 ms
79,336 KB |
testcase_49 | AC | 97 ms
77,312 KB |
testcase_50 | AC | 70 ms
71,168 KB |
testcase_51 | AC | 139 ms
78,776 KB |
testcase_52 | AC | 99 ms
77,360 KB |
testcase_53 | AC | 61 ms
66,688 KB |
testcase_54 | AC | 68 ms
69,504 KB |
testcase_55 | AC | 67 ms
69,760 KB |
testcase_56 | AC | 65 ms
67,968 KB |
testcase_57 | AC | 66 ms
69,248 KB |
testcase_58 | AC | 126 ms
78,612 KB |
testcase_59 | AC | 85 ms
77,056 KB |
testcase_60 | AC | 174 ms
80,112 KB |
testcase_61 | AC | 151 ms
79,104 KB |
testcase_62 | AC | 44 ms
54,656 KB |
testcase_63 | AC | 43 ms
54,528 KB |
testcase_64 | AC | 52 ms
60,416 KB |
ソースコード
from collections import * class Maxflow: def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, u, v, c): self.G[u].append([v, c, len(self.G[v])]) self.G[v].append([u, 0, len(self.G[u]) - 1]) def bfs(self, s): D = [-1] * self.N D[s] = 0 Q = deque() Q.append(s) while Q: u = Q.popleft() for next, cap, _ in self.G[u]: if cap > 0 and D[next] < 0: D[next] = D[u] + 1 Q.append(next) return D def dfs(self, v, t, f, removed, D): if v == t: return f while removed[v] < len(self.G[v]): next, cap, rev = self.G[v][removed[v]] if cap > 0 and D[v] < D[next]: flow = self.dfs(next, t, min(f, cap), removed, D) if flow > 0: self.G[v][removed[v]][1] -= flow self.G[next][rev][1] += flow return flow removed[v] += 1 return 0 def calc_max_flow(self, s, t): flow = 0 while True: D = self.bfs(s) if D[t] < 0: return flow removed = [0] * self.N while True: f = self.dfs(s, t, 1e10, removed, D) if f == 0: break flow += f N, M = map(int, input().split()) S = [] w, b = 0, 0 for i in range(N): S.append(list(input())) w += S[i].count("w") b += S[i].count("b") start = N * M goal = start + 1 dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] G = Maxflow(N * M + 2) for i in range(N): for j in range(M): if S[i][j] == ".": continue if (i + j) % 2 == 0: G.add_edge(i * M + j, goal, 1) continue G.add_edge(start, i * M + j, 1) for k in range(4): x = i + dx[k] y = j + dy[k] if x < 0 or x > N - 1 or y < 0 or y > M - 1: continue if S[x][y] == ".": continue if S[i][j] != S[x][y]: G.add_edge(i * M + j, x * M + y, 1) ans = 0 mf = G.calc_max_flow(start, goal) ans += mf * 100 b, w = b - mf, w - mf ans += min(b, w) * 10 + max(b, w) - min(b, w) print(ans)