結果
問題 | No.421 しろくろチョコレート |
ユーザー | tcltk |
提出日時 | 2021-06-27 14:40:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 232 ms / 2,000 ms |
コード長 | 2,790 bytes |
コンパイル時間 | 455 ms |
コンパイル使用メモリ | 81,840 KB |
実行使用メモリ | 90,812 KB |
最終ジャッジ日時 | 2023-10-24 15:04:33 |
合計ジャッジ時間 | 13,525 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
85,764 KB |
testcase_01 | AC | 212 ms
89,296 KB |
testcase_02 | AC | 158 ms
88,588 KB |
testcase_03 | AC | 156 ms
88,120 KB |
testcase_04 | AC | 152 ms
88,440 KB |
testcase_05 | AC | 169 ms
88,576 KB |
testcase_06 | AC | 143 ms
88,020 KB |
testcase_07 | AC | 200 ms
88,912 KB |
testcase_08 | AC | 154 ms
88,536 KB |
testcase_09 | AC | 153 ms
88,336 KB |
testcase_10 | AC | 147 ms
88,096 KB |
testcase_11 | AC | 178 ms
89,328 KB |
testcase_12 | AC | 127 ms
85,760 KB |
testcase_13 | AC | 127 ms
85,760 KB |
testcase_14 | AC | 128 ms
85,760 KB |
testcase_15 | AC | 126 ms
85,764 KB |
testcase_16 | AC | 216 ms
89,548 KB |
testcase_17 | AC | 218 ms
89,636 KB |
testcase_18 | AC | 213 ms
89,572 KB |
testcase_19 | AC | 128 ms
85,760 KB |
testcase_20 | AC | 212 ms
89,292 KB |
testcase_21 | AC | 208 ms
89,276 KB |
testcase_22 | AC | 196 ms
89,288 KB |
testcase_23 | AC | 135 ms
85,760 KB |
testcase_24 | AC | 134 ms
85,764 KB |
testcase_25 | AC | 127 ms
85,760 KB |
testcase_26 | AC | 130 ms
85,764 KB |
testcase_27 | AC | 132 ms
85,760 KB |
testcase_28 | AC | 173 ms
89,324 KB |
testcase_29 | AC | 184 ms
89,344 KB |
testcase_30 | AC | 195 ms
89,820 KB |
testcase_31 | AC | 200 ms
90,404 KB |
testcase_32 | AC | 195 ms
89,412 KB |
testcase_33 | AC | 191 ms
89,288 KB |
testcase_34 | AC | 139 ms
88,104 KB |
testcase_35 | AC | 141 ms
88,304 KB |
testcase_36 | AC | 186 ms
88,972 KB |
testcase_37 | AC | 224 ms
89,560 KB |
testcase_38 | AC | 217 ms
89,820 KB |
testcase_39 | AC | 172 ms
88,832 KB |
testcase_40 | AC | 198 ms
89,352 KB |
testcase_41 | AC | 159 ms
88,512 KB |
testcase_42 | AC | 165 ms
88,532 KB |
testcase_43 | AC | 181 ms
89,312 KB |
testcase_44 | AC | 200 ms
89,560 KB |
testcase_45 | AC | 155 ms
88,560 KB |
testcase_46 | AC | 156 ms
88,500 KB |
testcase_47 | AC | 200 ms
88,992 KB |
testcase_48 | AC | 203 ms
89,820 KB |
testcase_49 | AC | 162 ms
88,636 KB |
testcase_50 | AC | 154 ms
88,460 KB |
testcase_51 | AC | 202 ms
89,556 KB |
testcase_52 | AC | 185 ms
88,916 KB |
testcase_53 | AC | 161 ms
88,632 KB |
testcase_54 | AC | 160 ms
88,452 KB |
testcase_55 | AC | 157 ms
88,104 KB |
testcase_56 | AC | 156 ms
88,092 KB |
testcase_57 | AC | 167 ms
88,716 KB |
testcase_58 | AC | 198 ms
89,352 KB |
testcase_59 | AC | 176 ms
88,664 KB |
testcase_60 | AC | 224 ms
90,084 KB |
testcase_61 | AC | 232 ms
90,812 KB |
testcase_62 | AC | 136 ms
85,764 KB |
testcase_63 | AC | 135 ms
85,764 KB |
testcase_64 | AC | 132 ms
86,192 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)