結果
問題 | No.421 しろくろチョコレート |
ユーザー | 👑 rin204 |
提出日時 | 2022-07-12 19:00:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 148 ms / 2,000 ms |
コード長 | 2,411 bytes |
コンパイル時間 | 490 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 79,532 KB |
最終ジャッジ日時 | 2024-06-23 16:53:52 |
合計ジャッジ時間 | 8,136 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
54,656 KB |
testcase_01 | AC | 122 ms
78,548 KB |
testcase_02 | AC | 90 ms
77,312 KB |
testcase_03 | AC | 57 ms
66,944 KB |
testcase_04 | AC | 71 ms
73,984 KB |
testcase_05 | AC | 81 ms
76,684 KB |
testcase_06 | AC | 60 ms
66,560 KB |
testcase_07 | AC | 93 ms
77,012 KB |
testcase_08 | AC | 79 ms
77,056 KB |
testcase_09 | AC | 74 ms
74,576 KB |
testcase_10 | AC | 64 ms
70,400 KB |
testcase_11 | AC | 99 ms
77,248 KB |
testcase_12 | AC | 42 ms
54,016 KB |
testcase_13 | AC | 41 ms
54,328 KB |
testcase_14 | AC | 40 ms
54,272 KB |
testcase_15 | AC | 40 ms
53,760 KB |
testcase_16 | AC | 118 ms
78,792 KB |
testcase_17 | AC | 139 ms
79,064 KB |
testcase_18 | AC | 141 ms
78,688 KB |
testcase_19 | AC | 40 ms
53,936 KB |
testcase_20 | AC | 118 ms
78,276 KB |
testcase_21 | AC | 127 ms
78,436 KB |
testcase_22 | AC | 99 ms
77,220 KB |
testcase_23 | AC | 40 ms
54,144 KB |
testcase_24 | AC | 41 ms
54,272 KB |
testcase_25 | AC | 41 ms
54,144 KB |
testcase_26 | AC | 39 ms
54,200 KB |
testcase_27 | AC | 39 ms
53,888 KB |
testcase_28 | AC | 109 ms
77,448 KB |
testcase_29 | AC | 112 ms
78,380 KB |
testcase_30 | AC | 116 ms
78,500 KB |
testcase_31 | AC | 102 ms
79,520 KB |
testcase_32 | AC | 119 ms
78,544 KB |
testcase_33 | AC | 113 ms
77,784 KB |
testcase_34 | AC | 63 ms
70,784 KB |
testcase_35 | AC | 59 ms
69,376 KB |
testcase_36 | AC | 107 ms
77,712 KB |
testcase_37 | AC | 137 ms
78,824 KB |
testcase_38 | AC | 147 ms
79,152 KB |
testcase_39 | AC | 94 ms
77,676 KB |
testcase_40 | AC | 125 ms
78,132 KB |
testcase_41 | AC | 80 ms
76,628 KB |
testcase_42 | AC | 71 ms
74,492 KB |
testcase_43 | AC | 96 ms
77,296 KB |
testcase_44 | AC | 122 ms
78,480 KB |
testcase_45 | AC | 80 ms
77,220 KB |
testcase_46 | AC | 87 ms
76,972 KB |
testcase_47 | AC | 117 ms
78,236 KB |
testcase_48 | AC | 123 ms
78,916 KB |
testcase_49 | AC | 97 ms
77,184 KB |
testcase_50 | AC | 69 ms
73,892 KB |
testcase_51 | AC | 117 ms
77,952 KB |
testcase_52 | AC | 97 ms
77,472 KB |
testcase_53 | AC | 70 ms
75,008 KB |
testcase_54 | AC | 84 ms
77,048 KB |
testcase_55 | AC | 66 ms
71,552 KB |
testcase_56 | AC | 60 ms
69,504 KB |
testcase_57 | AC | 71 ms
73,984 KB |
testcase_58 | AC | 121 ms
78,428 KB |
testcase_59 | AC | 81 ms
76,524 KB |
testcase_60 | AC | 148 ms
79,044 KB |
testcase_61 | AC | 139 ms
79,532 KB |
testcase_62 | AC | 41 ms
54,784 KB |
testcase_63 | AC | 41 ms
54,272 KB |
testcase_64 | AC | 47 ms
60,792 KB |
ソースコード
from collections import deque class Dinic: def __init__(self, n): self.n = n self.links = [[] for _ in range(n)] self.depth = None self.progress = None def add_link(self, _from, to, cap): self.links[_from].append([cap, to, len(self.links[to])]) self.links[to].append([0, _from, len(self.links[_from]) - 1]) def bfs(self, s): depth = [-1] * self.n depth[s] = 0 q = deque([s]) while q: v = q.popleft() for cap, to, rev in self.links[v]: if cap > 0 and depth[to] < 0: depth[to] = depth[v] + 1 q.append(to) self.depth = depth def dfs(self, v, t, flow): if v == t: return flow links_v = self.links[v] for i in range(self.progress[v], len(links_v)): self.progress[v] = i cap, to, rev = link = links_v[i] if cap == 0 or self.depth[v] >= self.depth[to]: continue d = self.dfs(to, t, min(flow, cap)) if d == 0: continue link[0] -= d self.links[to][rev][0] += d return d return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) if self.depth[t] < 0: return flow self.progress = [0] * self.n current_flow = self.dfs(s, t, float('inf')) while current_flow > 0: flow += current_flow current_flow = self.dfs(s, t, float('inf')) n, m = map(int, input().split()) S = [input() for _ in range(n)] directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] G = Dinic(n * m + 2) s = n * m t = s + 1 f = lambda i, j: i * m + j b = 0 w = 0 for i in range(n): for j in range(m): if S[i][j] == ".": continue p = f(i, j) if S[i][j] == "w": w += 1 G.add_link(s, p, 1) for di, dj in directions: ni = i + di nj = j + dj if ni == -1 or ni == n or nj == -1 or nj == m: continue G.add_link(p, f(ni, nj), 1) else: b += 1 G.add_link(p, t, 1) fl = G.max_flow(s, t) ans = fl * 100 b -= fl w -= fl ans += min(b, w) * 10 ans += max(b, w) - min(b, w) print(ans)