結果

問題 No.179 塗り分け
ユーザー sue_charosue_charo
提出日時 2017-04-13 18:09:36
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 248 ms / 3,000 ms
コード長 1,183 bytes
コンパイル時間 588 ms
コンパイル使用メモリ 10,788 KB
実行使用メモリ 8,808 KB
最終ジャッジ日時 2023-09-30 20:54:11
合計ジャッジ時間 3,999 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,596 KB
testcase_01 AC 19 ms
8,680 KB
testcase_02 AC 19 ms
8,684 KB
testcase_03 AC 19 ms
8,668 KB
testcase_04 AC 19 ms
8,520 KB
testcase_05 AC 29 ms
8,624 KB
testcase_06 AC 19 ms
8,736 KB
testcase_07 AC 19 ms
8,616 KB
testcase_08 AC 60 ms
8,700 KB
testcase_09 AC 100 ms
8,680 KB
testcase_10 AC 19 ms
8,616 KB
testcase_11 AC 19 ms
8,648 KB
testcase_12 AC 115 ms
8,676 KB
testcase_13 AC 19 ms
8,656 KB
testcase_14 AC 19 ms
8,680 KB
testcase_15 AC 19 ms
8,636 KB
testcase_16 AC 18 ms
8,700 KB
testcase_17 AC 19 ms
8,552 KB
testcase_18 AC 20 ms
8,668 KB
testcase_19 AC 20 ms
8,584 KB
testcase_20 AC 80 ms
8,804 KB
testcase_21 AC 135 ms
8,636 KB
testcase_22 AC 248 ms
8,636 KB
testcase_23 AC 19 ms
8,624 KB
testcase_24 AC 105 ms
8,684 KB
testcase_25 AC 19 ms
8,780 KB
testcase_26 AC 60 ms
8,796 KB
testcase_27 AC 83 ms
8,740 KB
testcase_28 AC 51 ms
8,636 KB
testcase_29 AC 81 ms
8,808 KB
testcase_30 AC 65 ms
8,636 KB
testcase_31 AC 81 ms
8,692 KB
testcase_32 AC 29 ms
8,784 KB
testcase_33 AC 85 ms
8,724 KB
testcase_34 AC 57 ms
8,636 KB
testcase_35 AC 85 ms
8,720 KB
testcase_36 AC 19 ms
8,540 KB
testcase_37 AC 19 ms
8,744 KB
testcase_38 AC 18 ms
8,600 KB
testcase_39 AC 19 ms
8,680 KB
testcase_40 AC 19 ms
8,548 KB
testcase_41 AC 19 ms
8,640 KB
testcase_42 AC 19 ms
8,548 KB
testcase_43 AC 22 ms
8,696 KB
testcase_44 AC 29 ms
8,724 KB
testcase_45 AC 19 ms
8,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
from collections import deque

H, W = map(int, input().split())
# board[H][W]
board = [list(input()) for __ in range(H)]

index_board = [[c == "#" for c in row] for row in board]


def solve(check_board):
    if has_no_sharp(check_board):
        return False

    for h in range(H):
        for w in range(W):
            if h == w == 0:
                continue
            if check_paint(h, w, check_board):
                return True


def has_no_sharp(check_board):
    for row in check_board:
        if any(row):
            return False
    return True


def check_paint(h, w, check_board):
    copy_board = [row[:] for row in check_board]

    for h_ano in range(H):
        for w_ano in range(W):
            if copy_board[h_ano][w_ano]:
                if h_ano + h >= H or w_ano + w >= W or not copy_board[h_ano + h][w_ano + w]:
                    return False
                else:
                    copy_board[h_ano + h][w_ano + w] = False
    return True


if solve(index_board):
    print("YES")
else:
    board_reverse = [list(reversed(row)) for row in index_board]
    if solve(board_reverse):
        print("YES")
    else:
        print("NO")
0