結果

問題 No.179 塗り分け
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-03-04 22:01:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 622 ms / 3,000 ms
コード長 1,493 bytes
コンパイル時間 1,217 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 78,692 KB
最終ジャッジ日時 2023-09-30 20:46:31
合計ジャッジ時間 7,771 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
71,700 KB
testcase_01 AC 97 ms
71,692 KB
testcase_02 AC 98 ms
71,844 KB
testcase_03 AC 98 ms
71,812 KB
testcase_04 AC 98 ms
71,644 KB
testcase_05 AC 97 ms
71,516 KB
testcase_06 AC 103 ms
76,308 KB
testcase_07 AC 103 ms
76,412 KB
testcase_08 AC 120 ms
77,648 KB
testcase_09 AC 120 ms
77,800 KB
testcase_10 AC 117 ms
77,768 KB
testcase_11 AC 117 ms
77,664 KB
testcase_12 AC 622 ms
78,336 KB
testcase_13 AC 98 ms
71,492 KB
testcase_14 AC 97 ms
71,876 KB
testcase_15 AC 95 ms
71,352 KB
testcase_16 AC 96 ms
71,860 KB
testcase_17 AC 94 ms
71,352 KB
testcase_18 AC 113 ms
77,588 KB
testcase_19 AC 113 ms
77,668 KB
testcase_20 AC 103 ms
76,776 KB
testcase_21 AC 100 ms
76,492 KB
testcase_22 AC 137 ms
78,544 KB
testcase_23 AC 105 ms
77,024 KB
testcase_24 AC 133 ms
78,084 KB
testcase_25 AC 102 ms
76,452 KB
testcase_26 AC 110 ms
76,616 KB
testcase_27 AC 143 ms
78,620 KB
testcase_28 AC 112 ms
77,228 KB
testcase_29 AC 155 ms
78,460 KB
testcase_30 AC 136 ms
78,548 KB
testcase_31 AC 171 ms
78,460 KB
testcase_32 AC 140 ms
78,692 KB
testcase_33 AC 171 ms
78,512 KB
testcase_34 AC 123 ms
77,668 KB
testcase_35 AC 176 ms
78,556 KB
testcase_36 AC 96 ms
71,860 KB
testcase_37 AC 94 ms
71,512 KB
testcase_38 AC 96 ms
71,824 KB
testcase_39 AC 99 ms
71,836 KB
testcase_40 AC 98 ms
71,636 KB
testcase_41 AC 99 ms
71,632 KB
testcase_42 AC 99 ms
71,544 KB
testcase_43 AC 106 ms
76,004 KB
testcase_44 AC 120 ms
77,632 KB
testcase_45 AC 101 ms
76,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3
# -*- coding: utf-8 -*-

import array
import collections
import itertools


IS_RED = 1
IS_BLUE = 2


def solve(height, width, black_cells):
    num_black_cells = len(black_cells)
    if num_black_cells == 0:
        return False
    elif num_black_cells % 2 == 1:
        return False
    it_a = ((0, dc) for dc in range(1, width))
    it_b = itertools.product(range(1, height), range(-width + 1, width))
    for dr, dc in itertools.chain(it_a, it_b):
        counter = 0
        painted = collections.defaultdict(int)
        for r0, c0 in black_cells:
            if counter >= num_black_cells:
                return True
            (r, c) = (r0 + dr, c0 + dc)
            if r < 0 or r >= height or c < 0 or c >= width:
                if not painted[(r0, c0)]:
                    break
            elif (not painted[(r0, c0)]) and (not painted[(r, c)]):
                if (r, c) not in black_cells:
                    break
                painted[(r0, c0)] = IS_RED
                painted[(r, c)] = IS_BLUE
                counter += 2
        else:
            return True
    else:
        return False


def main():
    h, w = map(int, input().split())
    black_cells = []
    for r in range(h):
        for c, cell in enumerate(input()):
            if cell == "#":
                black_cells.append((r, c))
    black_cells.sort()
    if solve(h, w, black_cells):
        print("YES")
    else:
        print("NO")


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