結果

問題 No.179 塗り分け
ユーザー fgshun
提出日時 2020-09-27 11:49:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,279 ms / 3,000 ms
コード長 1,025 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 81,152 KB
最終ジャッジ日時 2024-07-23 15:22:23
合計ジャッジ時間 22,588 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import itertools
import copy

def _pred(move_x, move_y, H, W, s):
    if move_x == 0 and move_y == 0:
        return False
    for x, y in itertools.product(range(H), range(W)):
        if s[x][y] == 'b':
            s[x][y] = 'R'
            x2 = x + move_x
            y2 = y + move_y
            if 0 <= x2 < H and 0 <= y2 < W and s[x2][y2] == 'b':
                s[x2][y2] = 'B'
            else:
                return False

    return True


def resolve(in_):
    H, W = map(int, next(in_).split())
    black = ord(b'#')
    white = ord(b' ')

    S = []
    for s in itertools.islice(in_, H):
        S.append(['b' if i == black else 'w' for i in s.rstrip()])
    
    if all('b' not in s for s in S):
        return 'NO'

    ans = any(_pred(move_x, move_y, H, W, copy.deepcopy(S)) for move_x, move_y in itertools.product(range(-H + 1, H), range(-W + 1, W)))

    return 'YES' if ans else 'NO'
    

def main():
    ans = resolve(sys.stdin.buffer)

    print(ans)


if __name__ == '__main__':
    main()
0