結果

問題 No.179 塗り分け
ユーザー fgshun
提出日時 2020-09-27 11:45:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,025 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 17,824 KB
最終ジャッジ日時 2024-06-30 11:51:59
合計ジャッジ時間 6,128 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 2 TLE * 1 -- * 37
権限があれば一括ダウンロードができます

ソースコード

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