結果

問題 No.179 塗り分け
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-03-04 21:55:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,548 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 18,336 KB
最終ジャッジ日時 2024-04-14 05:59:40
合計ジャッジ時間 9,166 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,008 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 32 ms
10,880 KB
testcase_03 AC 32 ms
11,008 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 32 ms
11,008 KB
testcase_06 AC 32 ms
10,880 KB
testcase_07 AC 32 ms
11,008 KB
testcase_08 AC 1,888 ms
11,392 KB
testcase_09 AC 1,770 ms
11,392 KB
testcase_10 AC 84 ms
11,392 KB
testcase_11 AC 76 ms
11,392 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import array
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
    deltas = [(0, dc) for dc in range(1, width)]
    prod = itertools.product(range(1, height), range(-width + 1, width))
    deltas += [(dr, dc) for dr, dc in prod]
    for dr, dc in deltas:
        counter = 0
        painted = [array.array("B", (0 for _ in range(width)))
                   for _ in range(height)]
        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 painted[r0][c0] == 0 and painted[r][c] == 0:
                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