結果
問題 | No.421 しろくろチョコレート |
ユーザー | roaris |
提出日時 | 2019-11-01 14:33:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,029 bytes |
コンパイル時間 | 1,218 ms |
コンパイル使用メモリ | 86,972 KB |
実行使用メモリ | 78,784 KB |
最終ジャッジ日時 | 2023-10-13 00:46:53 |
合計ジャッジ時間 | 10,651 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 97 ms
71,676 KB |
testcase_01 | WA | - |
testcase_02 | AC | 109 ms
77,024 KB |
testcase_03 | WA | - |
testcase_04 | AC | 108 ms
77,020 KB |
testcase_05 | WA | - |
testcase_06 | AC | 101 ms
76,300 KB |
testcase_07 | WA | - |
testcase_08 | AC | 112 ms
77,220 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 93 ms
71,872 KB |
testcase_13 | AC | 93 ms
71,648 KB |
testcase_14 | AC | 94 ms
71,628 KB |
testcase_15 | AC | 94 ms
71,816 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 94 ms
71,832 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 94 ms
71,648 KB |
testcase_24 | AC | 93 ms
71,628 KB |
testcase_25 | AC | 94 ms
71,712 KB |
testcase_26 | AC | 93 ms
71,628 KB |
testcase_27 | AC | 94 ms
71,648 KB |
testcase_28 | AC | 119 ms
77,488 KB |
testcase_29 | AC | 130 ms
78,068 KB |
testcase_30 | WA | - |
testcase_31 | AC | 120 ms
77,492 KB |
testcase_32 | AC | 133 ms
78,196 KB |
testcase_33 | WA | - |
testcase_34 | AC | 105 ms
76,820 KB |
testcase_35 | AC | 106 ms
76,896 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 118 ms
77,448 KB |
testcase_41 | AC | 103 ms
77,060 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 130 ms
78,044 KB |
testcase_45 | WA | - |
testcase_46 | AC | 103 ms
77,008 KB |
testcase_47 | WA | - |
testcase_48 | AC | 118 ms
77,584 KB |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 118 ms
77,480 KB |
testcase_52 | WA | - |
testcase_53 | AC | 110 ms
77,548 KB |
testcase_54 | AC | 112 ms
77,276 KB |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | AC | 96 ms
71,472 KB |
testcase_63 | AC | 95 ms
71,504 KB |
testcase_64 | AC | 105 ms
77,040 KB |
ソースコード
from collections import defaultdict class Unionfind: def __init__(self, N): self.par = [-1] * N self.rank = [1] * N def root(self, x): if self.par[x] < 0: return x self.par[x] = self.root(self.par[x]) return self.par[x] def unite(self, x, y): rx, ry = self.root(x), self.root(y) if rx != ry: if self.rank[rx] >= self.rank[ry]: self.par[rx] += self.par[ry] self.par[ry] = rx if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 else: self.par[ry] += self.par[rx] self.par[rx] = ry def is_same(self, x, y): return self.root(x) == self.root(y) def count(self, x): return -self.par[self.root(x)] N, M = map(int, input().split()) S = [input() for _ in range(N)] uf = Unionfind(N*M) for i in range(N): for j in range(M): if S[i][j] != '.': for ni, nj in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]: if 0<=ni<N and 0<=nj<M and S[ni][nj] != '.': uf.unite(M*i+j, M*ni+nj) group = defaultdict(dict) for i in range(N): for j in range(M): if S[i][j] == 'w': if 0 not in group[uf.root(M*i+j)]: group[uf.root(M*i+j)][0] = 1 else: group[uf.root(M*i+j)][0] += 1 elif S[i][j] == 'b': if 1 not in group[uf.root(M*i+j)]: group[uf.root(M*i+j)][1]= 1 else: group[uf.root(M*i+j)][1] += 1 for k in group: if 0 not in group[k]: group[k][0] = 0 if 1 not in group[k]: group[k][1] = 0 pair_sum = 0 w_amari = 0 b_amari = 0 for k in group: pair = min(group[k][0], group[k][1]) pair_sum += pair w_amari += group[k][0]-pair b_amari += group[k][1]-pair print(pair_sum*100+min(w_amari, b_amari)*10+abs(w_amari-b_amari))