結果

問題 No.179 塗り分け
ユーザー masayamatu
提出日時 2020-05-05 22:37:26
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 658 ms / 3,000 ms
コード長 840 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-07-23 15:14:04
合計ジャッジ時間 4,721 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
S = []
for i in range(H):
    S.append([c for c in input()])

black = sum(S[i].count("#") for i in range(H))

if black % 2 == 1 or black == 0:
    print("NO")
    exit()
for h in range(H):
    for w in range(-W + 1,W):
        if h == 0 and w <= 0:
            continue
        s = [row[:] for row in S]
        cnt = 0
        flg = False
        for i in range(H):
            for j in range(W):
                if s[i][j] == "#":
                    if 0 <= i + h <H and 0 <= j+w < W and s[i+h][j+w] == "#":
                        s[i][j] = "r"
                        s[i+h][j+w] = "b"
                        cnt += 2
                    else:
                        flg = True
            if flg:
                break
        if cnt == black:
            print("YES")
            exit()
print("NO")
0