結果
問題 | No.421 しろくろチョコレート |
ユーザー |
|
提出日時 | 2023-06-17 14:07:58 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,560 bytes |
コンパイル時間 | 172 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 78,208 KB |
最終ジャッジ日時 | 2024-06-25 04:48:05 |
合計ジャッジ時間 | 6,860 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 WA * 33 |
ソースコード
from collections import *from itertools import *from functools import *from heapq import *import sys,mathinput = sys.stdin.readlineclass DSU:def __init__(self, n):self._n = nself.parent_or_size = [-1] * nself.member = [[i] for i in range(n)]def merge(self, a, b):assert 0 <= a < self._nassert 0 <= b < self._nx, y = self.leader(a), self.leader(b)if x == y: return xif -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, xself.parent_or_size[x] += self.parent_or_size[y]for tmp in self.member[y]:self.member[x].append(tmp)self.parent_or_size[y] = xreturn xdef members(self,a):return self.member[self.leader(a)]def same(self, a, b):assert 0 <= a < self._nassert 0 <= b < self._nreturn self.leader(a) == self.leader(b)def leader(self, a):assert 0 <= a < self._nif self.parent_or_size[a] < 0: return aself.parent_or_size[a] = self.leader(self.parent_or_size[a])return self.parent_or_size[a]def size(self, a):assert 0 <= a < self._nreturn -self.parent_or_size[self.leader(a)]def groups(self):leader_buf = [self.leader(i) for i in range(self._n)]result = [[] for _ in range(self._n)]for i in range(self._n): result[leader_buf[i]].append(i)return [r for r in result if r != []]N,M = map(int,input().split())S = [list(input())[:-1] for _ in range(N)]H,W = N,Mif H>W:H,W = W,HS = list(zip(*S))def nb(x,y):tmp = []if x+1<H:tmp.append((x+1,y))if x-1>=0:tmp.append((x-1,y))if y+1<W:tmp.append((x,y+1))if y-1>=0:tmp.append((x,y-1))return tmpD = DSU(N*M)for i in range(H):for j in range(W):if S[i][j]=='.':continuefor ix,iy in nb(i,j):if S[ix][iy]!='.':D.merge(W*ix + iy,W*i+j)C = Counter([])ans = 0for g in D.groups():i,j = divmod(g[0],W)if S[i][j]=='.':continueb = 0w = 0for i in g:ix,iy = divmod(i,W)if S[ix][iy]=='w':w += 1else:b += 1if b==w:ans += b*100elif b>w:ans += w*100C['b'] += b-welse:b,w = w,bans += w*100C['w'] += b-wa,b = C['b'],C['w']M = max(a,b)m = min(a,b)ans += 10*mans += (M-m)print(ans)