結果
問題 | No.421 しろくろチョコレート |
ユーザー | brthyyjp |
提出日時 | 2021-03-02 06:34:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 2,482 bytes |
コンパイル時間 | 264 ms |
コンパイル使用メモリ | 81,932 KB |
実行使用メモリ | 79,284 KB |
最終ジャッジ日時 | 2024-09-23 07:31:28 |
合計ジャッジ時間 | 7,370 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
55,104 KB |
testcase_01 | AC | 123 ms
78,104 KB |
testcase_02 | AC | 70 ms
71,760 KB |
testcase_03 | AC | 55 ms
64,196 KB |
testcase_04 | AC | 67 ms
71,052 KB |
testcase_05 | AC | 72 ms
72,752 KB |
testcase_06 | AC | 51 ms
62,360 KB |
testcase_07 | AC | 94 ms
77,112 KB |
testcase_08 | AC | 69 ms
70,880 KB |
testcase_09 | AC | 62 ms
68,256 KB |
testcase_10 | AC | 67 ms
69,516 KB |
testcase_11 | AC | 98 ms
77,184 KB |
testcase_12 | AC | 44 ms
54,384 KB |
testcase_13 | AC | 45 ms
55,288 KB |
testcase_14 | AC | 45 ms
55,300 KB |
testcase_15 | AC | 43 ms
55,492 KB |
testcase_16 | AC | 144 ms
79,008 KB |
testcase_17 | AC | 137 ms
78,740 KB |
testcase_18 | AC | 133 ms
78,772 KB |
testcase_19 | AC | 43 ms
54,104 KB |
testcase_20 | AC | 124 ms
78,388 KB |
testcase_21 | AC | 123 ms
78,604 KB |
testcase_22 | AC | 110 ms
77,500 KB |
testcase_23 | AC | 43 ms
54,700 KB |
testcase_24 | AC | 43 ms
54,800 KB |
testcase_25 | AC | 43 ms
54,320 KB |
testcase_26 | AC | 43 ms
55,752 KB |
testcase_27 | AC | 44 ms
54,452 KB |
testcase_28 | AC | 94 ms
77,612 KB |
testcase_29 | AC | 107 ms
77,740 KB |
testcase_30 | AC | 116 ms
78,268 KB |
testcase_31 | AC | 110 ms
79,284 KB |
testcase_32 | AC | 110 ms
77,628 KB |
testcase_33 | AC | 130 ms
78,812 KB |
testcase_34 | AC | 55 ms
65,540 KB |
testcase_35 | AC | 58 ms
65,620 KB |
testcase_36 | AC | 105 ms
77,468 KB |
testcase_37 | AC | 130 ms
78,956 KB |
testcase_38 | AC | 139 ms
79,140 KB |
testcase_39 | AC | 91 ms
77,200 KB |
testcase_40 | AC | 119 ms
78,448 KB |
testcase_41 | AC | 67 ms
71,436 KB |
testcase_42 | AC | 71 ms
72,160 KB |
testcase_43 | AC | 90 ms
77,236 KB |
testcase_44 | AC | 121 ms
78,764 KB |
testcase_45 | AC | 68 ms
70,220 KB |
testcase_46 | AC | 70 ms
71,472 KB |
testcase_47 | AC | 115 ms
77,396 KB |
testcase_48 | AC | 117 ms
78,948 KB |
testcase_49 | AC | 96 ms
77,468 KB |
testcase_50 | AC | 67 ms
70,372 KB |
testcase_51 | AC | 132 ms
78,628 KB |
testcase_52 | AC | 109 ms
77,304 KB |
testcase_53 | AC | 68 ms
69,868 KB |
testcase_54 | AC | 74 ms
73,064 KB |
testcase_55 | AC | 63 ms
69,104 KB |
testcase_56 | AC | 61 ms
67,772 KB |
testcase_57 | AC | 70 ms
72,552 KB |
testcase_58 | AC | 120 ms
78,012 KB |
testcase_59 | AC | 84 ms
76,612 KB |
testcase_60 | AC | 158 ms
79,252 KB |
testcase_61 | AC | 144 ms
79,072 KB |
testcase_62 | AC | 44 ms
56,012 KB |
testcase_63 | AC | 43 ms
55,420 KB |
testcase_64 | AC | 51 ms
62,944 KB |
ソースコード
from collections import deque class Dinic: def __init__(self, n, INF=float('inf')): self.n = n self.INF = INF self.pos = [] self.G = [[] for _ in range(n)] self.level = None self.iters = None def add_edge(self, fr, to, cap): self.pos.append((fr, len(self.G[fr]))) self.G[fr].append([cap, to, len(self.G[to])]) self.G[to].append([0, fr, len(self.G[fr])-1]) def bfs(self, s): level = [-1]*self.n level[s] = 0 q = deque([s]) while q: v = q.popleft() for cap, to, rev in self.G[v]: if cap > 0 and level[to] < 0: level[to] = level[v]+1 q.append(to) self.level = level def dfs(self, v, t, flow): if v == t: return flow for i in range(self.iters[v], len(self.G[v])): self.iters[v] = i cap, to, rev = self.G[v][i] if cap > 0 and self.level[v] < self.level[to]: d = self.dfs(to, t, min(flow, cap)) if d > 0: self.G[v][i][0] -= d self.G[to][rev][0] += d return d return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) if self.level[t] < 0: return flow self.iters = [0]*self.n f = self.dfs(s, t, self.INF) while f > 0: flow += f f = self.dfs(s, t, self.INF) n, m = map(int, input().split()) S = [input() for i in range(n)] INF = 10**9 dinic = Dinic(n*m+2, INF) w, b = 0, 0 s = n*m t = n*m+1 for i in range(n): for j in range(m): if (i+j)%2 == 0 and S[i][j] != '.': w += 1 dinic.add_edge(s, i*m+j, 1) # source > even if (i+j)%2 == 1 and S[i][j] != '.': b += 1 dinic.add_edge(i*m+j, t, 1) # odd > sink for i, row in enumerate(S): for j, c in enumerate(row): v = i*m+j if c == '.' or (i+j)%2 == 1: continue for di, dj in (-1, 0), (1, 0), (0, -1), (0, 1): ni, nj = i+di, j+dj if 0 <= ni < n and 0 <= nj < m: u = ni*m+nj if S[ni][nj] != '.': dinic.add_edge(v, u, 1) # even > odd f = dinic.max_flow(s, t) ans = 0 ans += f*100 w -= f b -= f ans += 10*min(w, b)+(max(w, b)-min(w,b)) print(ans)