結果

問題 No.421 しろくろチョコレート
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-06-17 14:07:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,560 bytes
コンパイル時間 1,755 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 80,964 KB
最終ジャッジ日時 2023-09-07 10:35:23
合計ジャッジ時間 13,491 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
72,332 KB
testcase_01 WA -
testcase_02 AC 128 ms
77,316 KB
testcase_03 WA -
testcase_04 AC 122 ms
77,348 KB
testcase_05 WA -
testcase_06 AC 110 ms
76,536 KB
testcase_07 WA -
testcase_08 AC 125 ms
77,608 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 107 ms
72,724 KB
testcase_13 AC 105 ms
72,212 KB
testcase_14 AC 103 ms
72,476 KB
testcase_15 AC 104 ms
72,420 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 103 ms
72,368 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 103 ms
72,368 KB
testcase_24 AC 112 ms
72,688 KB
testcase_25 AC 108 ms
72,224 KB
testcase_26 AC 107 ms
72,324 KB
testcase_27 AC 109 ms
72,320 KB
testcase_28 AC 149 ms
80,364 KB
testcase_29 AC 154 ms
80,636 KB
testcase_30 WA -
testcase_31 AC 138 ms
80,272 KB
testcase_32 AC 157 ms
80,136 KB
testcase_33 WA -
testcase_34 AC 121 ms
77,540 KB
testcase_35 AC 119 ms
77,440 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 134 ms
78,276 KB
testcase_41 AC 120 ms
77,228 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 137 ms
78,296 KB
testcase_45 WA -
testcase_46 AC 118 ms
77,708 KB
testcase_47 WA -
testcase_48 AC 133 ms
78,368 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 134 ms
78,424 KB
testcase_52 WA -
testcase_53 AC 118 ms
77,576 KB
testcase_54 AC 122 ms
77,772 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 106 ms
72,668 KB
testcase_63 AC 104 ms
72,332 KB
testcase_64 AC 116 ms
77,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline


class DSU:
    def __init__(self, n):
        self._n = n
        self.parent_or_size = [-1] * n
        self.member = [[i] for i in range(n)]

    def merge(self, a, b):
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        x, y = self.leader(a), self.leader(b)
        if x == y: return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x
        self.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] = x
        return x
        
    def members(self,a):
        
        return self.member[self.leader(a)]
    

    def same(self, a, b):
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        assert 0 <= a < self._n
        if self.parent_or_size[a] < 0: return a
        self.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._n
        return -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,M
if H>W:
    H,W = W,H
    S = 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 tmp
    
D = DSU(N*M)
for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            continue
        
        for ix,iy in nb(i,j):
            if S[ix][iy]!='.':
                D.merge(W*ix + iy,W*i+j)

C = Counter([])
ans = 0
for g in D.groups():
    
    i,j = divmod(g[0],W)
    if S[i][j]=='.':
        continue
    
    b = 0
    w = 0
    for i in g:
        ix,iy = divmod(i,W)
        if S[ix][iy]=='w':
            w += 1
        else:
            b += 1
    if b==w:
        ans += b*100
    elif b>w:
        ans += w*100
        C['b'] += b-w
    else:
        b,w = w,b
        ans += w*100
        C['w'] += b-w

a,b = C['b'],C['w']
M = max(a,b)
m = min(a,b)
ans += 10*m
ans += (M-m)
print(ans)
0