結果
問題 | No.421 しろくろチョコレート |
ユーザー | ああいい |
提出日時 | 2022-02-24 13:21:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 199 ms / 2,000 ms |
コード長 | 3,338 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 79,856 KB |
最終ジャッジ日時 | 2024-07-02 11:30:06 |
合計ジャッジ時間 | 8,504 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
54,528 KB |
testcase_01 | AC | 147 ms
78,832 KB |
testcase_02 | AC | 82 ms
71,424 KB |
testcase_03 | AC | 58 ms
62,336 KB |
testcase_04 | AC | 70 ms
66,816 KB |
testcase_05 | AC | 87 ms
72,448 KB |
testcase_06 | AC | 54 ms
60,416 KB |
testcase_07 | AC | 120 ms
77,440 KB |
testcase_08 | AC | 71 ms
67,200 KB |
testcase_09 | AC | 78 ms
69,760 KB |
testcase_10 | AC | 70 ms
66,176 KB |
testcase_11 | AC | 119 ms
77,392 KB |
testcase_12 | AC | 47 ms
54,272 KB |
testcase_13 | AC | 47 ms
54,272 KB |
testcase_14 | AC | 47 ms
54,144 KB |
testcase_15 | AC | 46 ms
54,144 KB |
testcase_16 | AC | 156 ms
78,976 KB |
testcase_17 | AC | 159 ms
79,116 KB |
testcase_18 | AC | 146 ms
79,312 KB |
testcase_19 | AC | 49 ms
54,400 KB |
testcase_20 | AC | 141 ms
78,592 KB |
testcase_21 | AC | 148 ms
78,708 KB |
testcase_22 | AC | 126 ms
77,500 KB |
testcase_23 | AC | 48 ms
54,400 KB |
testcase_24 | AC | 47 ms
54,272 KB |
testcase_25 | AC | 47 ms
54,016 KB |
testcase_26 | AC | 47 ms
54,144 KB |
testcase_27 | AC | 46 ms
54,144 KB |
testcase_28 | AC | 119 ms
77,876 KB |
testcase_29 | AC | 130 ms
78,232 KB |
testcase_30 | AC | 129 ms
77,824 KB |
testcase_31 | AC | 128 ms
79,576 KB |
testcase_32 | AC | 140 ms
78,556 KB |
testcase_33 | AC | 155 ms
78,976 KB |
testcase_34 | AC | 57 ms
61,952 KB |
testcase_35 | AC | 61 ms
62,976 KB |
testcase_36 | AC | 119 ms
77,384 KB |
testcase_37 | AC | 157 ms
79,128 KB |
testcase_38 | AC | 174 ms
78,976 KB |
testcase_39 | AC | 106 ms
77,440 KB |
testcase_40 | AC | 143 ms
78,500 KB |
testcase_41 | AC | 82 ms
71,168 KB |
testcase_42 | AC | 74 ms
68,864 KB |
testcase_43 | AC | 112 ms
77,312 KB |
testcase_44 | AC | 165 ms
79,068 KB |
testcase_45 | AC | 80 ms
70,912 KB |
testcase_46 | AC | 71 ms
66,816 KB |
testcase_47 | AC | 129 ms
78,080 KB |
testcase_48 | AC | 146 ms
79,364 KB |
testcase_49 | AC | 104 ms
77,312 KB |
testcase_50 | AC | 86 ms
72,960 KB |
testcase_51 | AC | 156 ms
78,820 KB |
testcase_52 | AC | 126 ms
77,788 KB |
testcase_53 | AC | 71 ms
67,328 KB |
testcase_54 | AC | 86 ms
72,704 KB |
testcase_55 | AC | 82 ms
70,784 KB |
testcase_56 | AC | 75 ms
68,736 KB |
testcase_57 | AC | 78 ms
70,016 KB |
testcase_58 | AC | 134 ms
78,360 KB |
testcase_59 | AC | 108 ms
76,928 KB |
testcase_60 | AC | 199 ms
79,668 KB |
testcase_61 | AC | 182 ms
79,856 KB |
testcase_62 | AC | 48 ms
54,400 KB |
testcase_63 | AC | 47 ms
54,272 KB |
testcase_64 | AC | 52 ms
60,928 KB |
ソースコード
#Dinic法で最大流を求める #deque のimport が必要 #逆辺追加しなきゃいけないから、 #グラフの構成はadd_edgeで行う #最大流は flow メソッドで from collections import deque class Dinic: def __init__(self,N): self.N = N self.G = [[] for _ in range(N)] self.level = None self.progress = None self.edge = [] def add_edge(self,fr,to,cap): forward = [to,cap,None] forward[2] = backward = [fr,0,forward] self.G[fr].append(forward) self.G[to].append(backward) self.edge.append(forward) def add_multi_edge(self,v1,v2,cap1,cap2): edge1 = [v2,cap1,None] edge1[2] = edge2 = [v1,cap2,edge1] self.G[v1].append(edge1) self.G[v2].append(edge2) self.edge.append(edge1) def get_edge(self,i): return self.edge[i] # i 回目に追加した辺のポインタを返す # 0-index, 順辺のみ def bfs(self,s,t): self.level = level = [None] * self.N q = deque([s]) level[s] = 0 G = self.G while q: v = q.popleft() lv = level[v] + 1 for w,cap,_ in G[v]: if cap and level[w] is None: level[w] = lv q.append(w) return level[t] is not None def dfs(self,v,t,f): if v == t:return f level = self.level Gv = self.G[v] for i in range(self.progress[v],len(Gv)): self.progress[v] = i w,cap,rev = e = Gv[i] if cap and level[v] < level[w]: d = self.dfs(w,t,min(f,cap)) if d: e[1] -= d rev[1] += d return d return 0 def flow(self,s,t,): flow = 0 inf = 1 << 30 G = self.G while self.bfs(s,t): self.progress = [0] * self.N f = inf while f: f = self.dfs(s,t,inf) flow += f return flow def min_cut(self,s): #最小カットを実現する頂点の分割を与える #True なら source側 #False なら sink側 visited = [False for i in range(self.N)] q = deque([s]) while q: now = q.popleft() visited[now] = True for to,cap,_ in self.G[now]: if cap and not visited[to]: visited[to] = True q.append(to) return visited N,M = map(int,input().split()) S = [input() for _ in range(N)] countb = 0 countw = 0 dinic = Dinic(N * M + 2) T = N * M + 1 def f(h,w): return h * M + w + 1 for h in range(N): for w in range(M): if S[h][w] == "w": countw += 1 dinic.add_edge(f(h,w),T,1) elif S[h][w] == "b": countb += 1 dinic.add_edge(0,f(h,w),1) for i,j in [(1,0),(-1,0),(0,1),(0,-1)]: if 0 <= h + i < N and 0 <= w + j < M: if S[h+i][w+j] == "w": dinic.add_edge(f(h,w),f(h+i,w+j),1) match = dinic.flow(0,T) countb -= match countw -= match num = min(countw,countb) countb -= num countw -= num ans = 100 * match + 10 * num + countb + countw print(ans)