結果
問題 | No.421 しろくろチョコレート |
ユーザー | tcltk |
提出日時 | 2021-06-27 14:40:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 238 ms / 2,000 ms |
コード長 | 2,790 bytes |
コンパイル時間 | 261 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 91,792 KB |
最終ジャッジ日時 | 2024-09-23 07:31:54 |
合計ジャッジ時間 | 13,339 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 135 ms
86,416 KB |
testcase_01 | AC | 223 ms
90,560 KB |
testcase_02 | AC | 163 ms
89,644 KB |
testcase_03 | AC | 146 ms
88,600 KB |
testcase_04 | AC | 153 ms
89,472 KB |
testcase_05 | AC | 167 ms
89,344 KB |
testcase_06 | AC | 146 ms
88,576 KB |
testcase_07 | AC | 196 ms
90,352 KB |
testcase_08 | AC | 156 ms
89,784 KB |
testcase_09 | AC | 155 ms
89,092 KB |
testcase_10 | AC | 150 ms
88,724 KB |
testcase_11 | AC | 182 ms
90,076 KB |
testcase_12 | AC | 131 ms
87,168 KB |
testcase_13 | AC | 131 ms
86,656 KB |
testcase_14 | AC | 130 ms
86,784 KB |
testcase_15 | AC | 129 ms
86,808 KB |
testcase_16 | AC | 218 ms
90,496 KB |
testcase_17 | AC | 225 ms
91,132 KB |
testcase_18 | AC | 223 ms
90,880 KB |
testcase_19 | AC | 132 ms
86,688 KB |
testcase_20 | AC | 207 ms
90,608 KB |
testcase_21 | AC | 210 ms
90,624 KB |
testcase_22 | AC | 193 ms
90,216 KB |
testcase_23 | AC | 133 ms
86,820 KB |
testcase_24 | AC | 131 ms
86,912 KB |
testcase_25 | AC | 131 ms
86,616 KB |
testcase_26 | AC | 130 ms
86,912 KB |
testcase_27 | AC | 131 ms
87,040 KB |
testcase_28 | AC | 179 ms
90,496 KB |
testcase_29 | AC | 183 ms
90,360 KB |
testcase_30 | AC | 197 ms
90,584 KB |
testcase_31 | AC | 202 ms
91,376 KB |
testcase_32 | AC | 189 ms
90,696 KB |
testcase_33 | AC | 196 ms
90,688 KB |
testcase_34 | AC | 144 ms
88,656 KB |
testcase_35 | AC | 146 ms
89,352 KB |
testcase_36 | AC | 197 ms
90,112 KB |
testcase_37 | AC | 217 ms
90,816 KB |
testcase_38 | AC | 217 ms
90,788 KB |
testcase_39 | AC | 165 ms
89,632 KB |
testcase_40 | AC | 201 ms
90,472 KB |
testcase_41 | AC | 160 ms
89,288 KB |
testcase_42 | AC | 168 ms
89,720 KB |
testcase_43 | AC | 184 ms
90,496 KB |
testcase_44 | AC | 203 ms
90,740 KB |
testcase_45 | AC | 158 ms
89,428 KB |
testcase_46 | AC | 159 ms
89,524 KB |
testcase_47 | AC | 204 ms
90,232 KB |
testcase_48 | AC | 207 ms
90,968 KB |
testcase_49 | AC | 166 ms
89,856 KB |
testcase_50 | AC | 161 ms
89,420 KB |
testcase_51 | AC | 212 ms
90,604 KB |
testcase_52 | AC | 203 ms
90,240 KB |
testcase_53 | AC | 161 ms
89,240 KB |
testcase_54 | AC | 164 ms
89,424 KB |
testcase_55 | AC | 153 ms
88,900 KB |
testcase_56 | AC | 148 ms
89,344 KB |
testcase_57 | AC | 164 ms
89,628 KB |
testcase_58 | AC | 204 ms
90,620 KB |
testcase_59 | AC | 170 ms
89,564 KB |
testcase_60 | AC | 231 ms
91,264 KB |
testcase_61 | AC | 238 ms
91,792 KB |
testcase_62 | AC | 133 ms
86,604 KB |
testcase_63 | AC | 133 ms
86,800 KB |
testcase_64 | AC | 136 ms
87,196 KB |
ソースコード
#!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq def input(): return sys.stdin.readline()[:-1] # sys.setrecursionlimit(1000000) # _INPUT = """# paste here... # """ # sys.stdin = io.StringIO(_INPUT) 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 = collections.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, INF) while current_flow > 0: flow += current_flow current_flow = self.dfs(s, t, INF) INF = 10**10 H, W = map(int, input().split()) S = [input() for _ in range(H)] # 2分グラフ: S -> (W) -> (B) -> T mf = Dinic(H*W+2) n_w, n_b = 0, 0 for h in range(H): for w in range(W): if S[h][w] == 'w': n_w += 1 mf.add_link(0, h*W+w+1, 1) if 0 < w and S[h][w-1] != '.': mf.add_link(h*W+w+1, h*W+(w-1)+1, 1) if w < W-1 and S[h][w+1] != '.': mf.add_link(h*W+w+1, h*W+(w+1)+1, 1) if 0 < h and S[h-1][w] != '.': mf.add_link(h*W+w+1, (h-1)*W+w+1, 1) if h < H-1 and S[h+1][w] != '.': mf.add_link(h*W+w+1, (h+1)*W+w+1, 1) elif S[h][w] == 'b': n_b += 1 mf.add_link(h*W+w+1, H*W+1, 1) flow = mf.max_flow(0, H*W+1) n_w -= flow n_b -= flow m = min(n_w, n_b) score = flow*100 + m*10 + (n_w-m) + (n_b-m) print(score)