結果

問題 No.421 しろくろチョコレート
ユーザー sonoyahmansonoyahman
提出日時 2016-10-30 20:26:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 3,041 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 11,092 KB
実行使用メモリ 8,644 KB
最終ジャッジ日時 2023-08-16 11:26:18
合計ジャッジ時間 4,605 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 17 ms
8,536 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 16 ms
8,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 AC 23 ms
8,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

"""入力"""
M,N = map(int, input().split()) 

#print (M,N)
Choco = []

for i in range(M):
    Choco.append(list(input()))

#print(Choco)


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

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

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箇所のみ接続
    #print(up,down,left,light,dummy)
    if sum3 == 3:
        connect = [i + up + down,j + left + light]#1箇所が接続している場合の3の場合の接続先
    else:
        connect =["*","*"]

    return (sum3,connect,dummy)
    



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

        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
    
    return(count_w,count_b)
    
"""アルゴ①""" 
while True:
    #print("アルゴ①--------------")
    count = 0
    for i in range(1,M+1):
        for j in range(1,N+1):
            #print("******")
            #print(i,j)
            flag = eat_three(i,j)
            if flag == True:
                count += 1
            #print("i:",i)        
    #print("アルゴ①",Choco)
    
    if count == 0:
        break

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

"""アルゴ③④"""
wb = [0,0]
for i in range(1,M+1):
    for j in range(1,N+1):
        if 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(Choco)
print(Point)
0