結果

問題 No.421 しろくろチョコレート
ユーザー sonoyahmansonoyahman
提出日時 2016-10-31 02:49:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 3,582 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 11,084 KB
実行使用メモリ 8,636 KB
最終ジャッジ日時 2023-08-16 11:30:24
合計ジャッジ時間 5,341 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,512 KB
testcase_01 WA -
testcase_02 AC 27 ms
8,488 KB
testcase_03 AC 19 ms
8,392 KB
testcase_04 AC 24 ms
8,500 KB
testcase_05 WA -
testcase_06 AC 19 ms
8,384 KB
testcase_07 WA -
testcase_08 AC 31 ms
8,400 KB
testcase_09 AC 22 ms
8,392 KB
testcase_10 AC 21 ms
8,564 KB
testcase_11 WA -
testcase_12 AC 16 ms
8,384 KB
testcase_13 AC 16 ms
8,460 KB
testcase_14 AC 17 ms
8,380 KB
testcase_15 AC 17 ms
8,452 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 17 ms
8,328 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 16 ms
8,500 KB
testcase_24 AC 16 ms
8,368 KB
testcase_25 AC 17 ms
8,412 KB
testcase_26 AC 16 ms
8,508 KB
testcase_27 AC 17 ms
8,328 KB
testcase_28 AC 27 ms
8,356 KB
testcase_29 AC 134 ms
8,496 KB
testcase_30 AC 78 ms
8,400 KB
testcase_31 AC 26 ms
8,052 KB
testcase_32 AC 121 ms
8,528 KB
testcase_33 AC 128 ms
8,536 KB
testcase_34 AC 27 ms
8,500 KB
testcase_35 AC 29 ms
8,444 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 29 ms
8,484 KB
testcase_40 WA -
testcase_41 AC 18 ms
8,372 KB
testcase_42 AC 22 ms
8,504 KB
testcase_43 AC 33 ms
8,416 KB
testcase_44 WA -
testcase_45 AC 23 ms
8,500 KB
testcase_46 AC 23 ms
8,476 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 34 ms
8,412 KB
testcase_50 AC 30 ms
8,380 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 22 ms
8,020 KB
testcase_54 AC 27 ms
8,488 KB
testcase_55 WA -
testcase_56 AC 21 ms
8,392 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 22 ms
8,376 KB
testcase_60 WA -
testcase_61 WA -
testcase_62 AC 17 ms
8,484 KB
testcase_63 AC 17 ms
8,356 KB
testcase_64 AC 25 ms
8,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
アルゴリズム概要
① 1方向だけ接続しているチョコを食べる。
② 残りに対して、ペアを削除
③ 独立したチョコを黒白マッチング
④ 残りチョコを食べる
"""

"""入力"""

M,N = map(int, input().split())
Choco = []
for i in range(M):
    Choco.append(list(input()))


"""
M = 50
N = 48


f = open("case_06.txt","r")
Choco = f.readlines()

for i in range(M):
    Choco[i] = Choco[i].strip()
    Choco[i] = list(Choco[i])
    
#print(Choco)
"""


"""チョコの周りに壁(.)を作成(端っこ判定用)"""
for i in range(M):
    Choco[i].insert(0,".")
    Choco[i].append(".")

Choco.insert(0,["."]*(N+2))
Choco.append(["."]*(N+2))


Point = 0

def jud(i,j):
    """周辺状況を判定する。"""
    up    = 0
    down  = 0
    left  = 0
    light = 0
    dummy = 0

    if Choco[i-1][j] == ".":
        up =  1

    if Choco[i+1][j] == ".":
        down = -1

    if Choco[i][j-1] == "." :
        left = 1

    if Choco[i][j+1] == ".":
        light = -1

    if Choco[i][j] == ".":
        dummy = 100

    sum3 = abs(up) + abs(down) + abs(left) + abs(light) + dummy #3だったら1箇所のみ接続
    sum4 = abs(up) + abs(down) + abs(left) + abs(light)  #独立判定
    #print(up,down,left,light,dummy)
    if sum3 == 3:
        connect = [i + up + down,j + left + light]#1箇所が接続している場合の3の場合の接続先
    else:
        connect =["*","*"]

    return (sum3,connect,dummy,sum4)
    



def eat_three(i,j):
    """ アルゴ①箇所だけ繋がっているものとその先のチョコを食べる"""
    a = jud(i,j)
    if a[0] == 3:
        Choco[i][j] = "."
        Choco[a[1][0]][a[1][1]] = "."
        global Point
        Point += 100

        return True

def eat_rec(i,j):
    if Choco[i][j] != ".":
        if Choco[i][j+1] != ".":
            Choco[i][j] = "."
            Choco[i][j+1] ="."
            global Point
            Point += 100

def count_wb(i,j):
    count_w = 0
    count_b = 0
    
    if Choco[i][j] != ".":
        if  Choco[i][j] == "w":
            count_w += 1
        else:
            count_b += 1
        
        #x = Choco[i][j]
        #Choco[i][j] = "."
        #y = Choco[i][j]
        #print(x,y)
    
    return(count_w,count_b)

"""
han =[0,0]
for i in range(1,M+1):
    for j in range(1,N+1):
        han[0] += count_wb(i,j)[0]
        han[1] += count_wb(i,j)[1]  
       
print(han)    
"""

"""アルゴ①""" 
while True:
    count = 0
    for i in range(1,M+1):
        for j in range(1,N+1):
            flag = eat_three(i,j)
            if flag == True:
                count += 1     
   # print("アルゴ①",Choco)
    
    if count == 0:
        break

#print("アルゴ①:",Point)
    
"""アルゴ②"""
for i in range(1,M+1):
    for j in range(1,N+1):
        #print("===",i,j)
        #print("②-1:",Choco[i][j])
        eat_rec(i,j)
        #print("②-2:",Choco[i][j])
    for j in range(1,N+1):
        eat_three(i,j) #奇数の場合の対応
        #print("②-3:",Choco[i][j])

#print("アルゴ②:",Point)

"""アルゴ③④"""
wb = [0,0]
for i in range(1,M+1):
    for j in range(1,N+1):
        #print(jud(i,j))
        if (jud(i,j)[3] == 4 and jud(i,j)[2] != 100):
            wb[0] += count_wb(i,j)[0]
            wb[1] += count_wb(i,j)[1]

#print(wb)
        
diff_wb = wb[0] - wb[1]
if diff_wb >= 0:
    Point += wb[1]*10 + diff_wb
    #print(Point)            
            
else:
    Point += wb[0]*10 - diff_wb
#print(diff_wb)
#print("アルゴ③:",Point)
#print(Choco)
print(Point)
0