結果
問題 | No.421 しろくろチョコレート |
ユーザー | ayaoni |
提出日時 | 2020-09-25 20:09:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 167 ms / 2,000 ms |
コード長 | 2,585 bytes |
コンパイル時間 | 223 ms |
コンパイル使用メモリ | 81,732 KB |
実行使用メモリ | 79,964 KB |
最終ジャッジ日時 | 2024-09-23 07:30:57 |
合計ジャッジ時間 | 7,145 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
55,152 KB |
testcase_01 | AC | 118 ms
78,040 KB |
testcase_02 | AC | 61 ms
66,808 KB |
testcase_03 | AC | 56 ms
64,028 KB |
testcase_04 | AC | 58 ms
66,452 KB |
testcase_05 | AC | 69 ms
70,988 KB |
testcase_06 | AC | 50 ms
62,020 KB |
testcase_07 | AC | 103 ms
77,300 KB |
testcase_08 | AC | 67 ms
70,000 KB |
testcase_09 | AC | 64 ms
67,176 KB |
testcase_10 | AC | 59 ms
66,840 KB |
testcase_11 | AC | 97 ms
77,700 KB |
testcase_12 | AC | 44 ms
54,780 KB |
testcase_13 | AC | 44 ms
55,252 KB |
testcase_14 | AC | 43 ms
55,208 KB |
testcase_15 | AC | 44 ms
55,704 KB |
testcase_16 | AC | 136 ms
79,676 KB |
testcase_17 | AC | 135 ms
79,480 KB |
testcase_18 | AC | 144 ms
79,344 KB |
testcase_19 | AC | 44 ms
55,952 KB |
testcase_20 | AC | 119 ms
78,184 KB |
testcase_21 | AC | 134 ms
79,180 KB |
testcase_22 | AC | 99 ms
77,736 KB |
testcase_23 | AC | 42 ms
55,924 KB |
testcase_24 | AC | 44 ms
55,144 KB |
testcase_25 | AC | 43 ms
54,660 KB |
testcase_26 | AC | 43 ms
54,544 KB |
testcase_27 | AC | 43 ms
55,440 KB |
testcase_28 | AC | 78 ms
75,080 KB |
testcase_29 | AC | 96 ms
78,148 KB |
testcase_30 | AC | 106 ms
78,024 KB |
testcase_31 | AC | 104 ms
79,376 KB |
testcase_32 | AC | 104 ms
78,296 KB |
testcase_33 | AC | 120 ms
78,712 KB |
testcase_34 | AC | 52 ms
63,160 KB |
testcase_35 | AC | 54 ms
64,604 KB |
testcase_36 | AC | 105 ms
77,952 KB |
testcase_37 | AC | 143 ms
79,504 KB |
testcase_38 | AC | 151 ms
79,640 KB |
testcase_39 | AC | 76 ms
73,844 KB |
testcase_40 | AC | 108 ms
77,924 KB |
testcase_41 | AC | 66 ms
69,964 KB |
testcase_42 | AC | 67 ms
70,096 KB |
testcase_43 | AC | 86 ms
77,648 KB |
testcase_44 | AC | 119 ms
78,552 KB |
testcase_45 | AC | 60 ms
66,904 KB |
testcase_46 | AC | 67 ms
71,320 KB |
testcase_47 | AC | 112 ms
77,832 KB |
testcase_48 | AC | 126 ms
79,668 KB |
testcase_49 | AC | 79 ms
73,620 KB |
testcase_50 | AC | 65 ms
67,184 KB |
testcase_51 | AC | 126 ms
78,368 KB |
testcase_52 | AC | 100 ms
77,716 KB |
testcase_53 | AC | 61 ms
67,316 KB |
testcase_54 | AC | 65 ms
69,300 KB |
testcase_55 | AC | 63 ms
68,256 KB |
testcase_56 | AC | 58 ms
66,456 KB |
testcase_57 | AC | 63 ms
69,076 KB |
testcase_58 | AC | 111 ms
77,960 KB |
testcase_59 | AC | 77 ms
72,788 KB |
testcase_60 | AC | 167 ms
79,964 KB |
testcase_61 | AC | 149 ms
79,460 KB |
testcase_62 | AC | 44 ms
55,764 KB |
testcase_63 | AC | 44 ms
54,736 KB |
testcase_64 | AC | 48 ms
61,444 KB |
ソースコード
from collections import deque class Dinic: def __init__(self, N, inf): self.N = N self.inf = inf self.G = [[] for _ in range(N)] self.level = [0]*N 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) 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) def bfs(self, s): self.level = [-1]*self.N deq = deque([s]) self.level[s] = 0 while deq: v = deq.pop() lv = self.level[v] + 1 for w, cap, _ in self.G[v]: if cap > 0 and self.level[w] == -1: self.level[w] = lv deq.appendleft(w) def dfs(self, v, t, f): if v == t: return f for e in self.iter[v]: w, cap, rev = e if cap > 0 and self.level[v] < self.level[w]: d = self.dfs(w, t, min(f, cap)) if d > 0: e[1] -= d rev[1] += d return d return 0 def flow(self, s, t): flow = 0 while True: self.bfs(s) if self.level[t] == -1: return flow *self.iter, = map(iter, self.G) f = self.inf while f > 0: f = self.dfs(s, t, self.inf) flow += f import sys sys.setrecursionlimit(10**7) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N,M = MI() S = [LS2() for _ in range(N)] Di = Dinic(N*M+2,10000) s,t = N*M,N*M+1 white,black = 0,0 for i in range(N): for j in range(M): if S[i][j] == '.': continue a = M*i+j if (i+j) % 2 == 0: white += 1 Di.add_edge(s,a,1) if 0 <= i-1 and S[i-1][j] != '.': Di.add_edge(a,M*(i-1)+j,1) if i+1 < N and S[i+1][j] != '.': Di.add_edge(a,M*(i+1)+j,1) if 0 <= j-1 and S[i][j-1] != '.': Di.add_edge(a,M*i+j-1,1) if j+1 < M and S[i][j+1] != '.': Di.add_edge(a,M*i+j+1,1) else: black += 1 Di.add_edge(a,t,1) flow = Di.flow(s,t) print(100*flow+10*(min(white,black)-flow)+(abs(white-black)))