結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,444 KB
testcase_01 WA -
testcase_02 AC 26 ms
8,368 KB
testcase_03 WA -
testcase_04 AC 23 ms
8,388 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 31 ms
8,404 KB
testcase_09 WA -
testcase_10 AC 21 ms
8,388 KB
testcase_11 WA -
testcase_12 AC 16 ms
8,444 KB
testcase_13 AC 16 ms
8,512 KB
testcase_14 AC 17 ms
8,536 KB
testcase_15 AC 16 ms
8,424 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 16 ms
8,172 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 17 ms
8,376 KB
testcase_24 AC 17 ms
8,420 KB
testcase_25 AC 16 ms
8,424 KB
testcase_26 AC 17 ms
8,440 KB
testcase_27 AC 16 ms
8,380 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 27 ms
8,520 KB
testcase_35 AC 29 ms
8,396 KB
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 AC 24 ms
8,508 KB
testcase_46 AC 23 ms
8,384 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 22 ms
8,516 KB
testcase_54 AC 27 ms
8,408 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 17 ms
8,488 KB
testcase_63 AC 17 ms
8,428 KB
testcase_64 AC 25 ms
8,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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


"""チョコの周りに壁(.)を作成(端っこ判定用)"""
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
    
    return(count_w,count_b)
    
"""アルゴ①""" 
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):
        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):
        #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("アルゴ③:",Point)
print(Point)
0