結果

問題 No.179 塗り分け
ユーザー CsTarepandaCsTarepanda
提出日時 2019-04-21 21:45:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 60 ms / 3,000 ms
コード長 1,143 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 8,724 KB
最終ジャッジ日時 2023-09-30 21:10:27
合計ジャッジ時間 2,678 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,400 KB
testcase_01 AC 19 ms
8,424 KB
testcase_02 AC 18 ms
8,584 KB
testcase_03 AC 19 ms
8,568 KB
testcase_04 AC 18 ms
8,416 KB
testcase_05 AC 18 ms
8,524 KB
testcase_06 AC 18 ms
8,472 KB
testcase_07 AC 18 ms
8,596 KB
testcase_08 AC 20 ms
8,636 KB
testcase_09 AC 19 ms
8,456 KB
testcase_10 AC 20 ms
8,648 KB
testcase_11 AC 19 ms
8,660 KB
testcase_12 AC 60 ms
8,724 KB
testcase_13 AC 19 ms
8,428 KB
testcase_14 AC 19 ms
8,520 KB
testcase_15 AC 18 ms
8,400 KB
testcase_16 AC 18 ms
8,572 KB
testcase_17 AC 18 ms
8,408 KB
testcase_18 AC 19 ms
8,508 KB
testcase_19 AC 19 ms
8,592 KB
testcase_20 AC 18 ms
8,588 KB
testcase_21 AC 18 ms
8,536 KB
testcase_22 AC 41 ms
8,568 KB
testcase_23 AC 19 ms
8,632 KB
testcase_24 AC 22 ms
8,580 KB
testcase_25 AC 19 ms
8,504 KB
testcase_26 AC 19 ms
8,588 KB
testcase_27 AC 22 ms
8,448 KB
testcase_28 AC 19 ms
8,480 KB
testcase_29 AC 25 ms
8,628 KB
testcase_30 AC 22 ms
8,588 KB
testcase_31 AC 28 ms
8,560 KB
testcase_32 AC 21 ms
8,584 KB
testcase_33 AC 28 ms
8,484 KB
testcase_34 AC 20 ms
8,516 KB
testcase_35 AC 28 ms
8,472 KB
testcase_36 AC 18 ms
8,600 KB
testcase_37 AC 18 ms
8,576 KB
testcase_38 AC 19 ms
8,572 KB
testcase_39 AC 18 ms
8,516 KB
testcase_40 AC 18 ms
8,420 KB
testcase_41 AC 18 ms
8,572 KB
testcase_42 AC 18 ms
8,516 KB
testcase_43 AC 19 ms
8,552 KB
testcase_44 AC 19 ms
8,436 KB
testcase_45 AC 18 ms
8,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import copy
h, w = map(int, input().split())
start_x, start_y = None, None

field = [list(input()) for _ in range(h)]
black_n = "".join(map("".join, field)).count("#")

if black_n > 0 and black_n % 2:
    print("NO")
    exit()


def check(y, x):
    global start_x, start_y
    if field[y][x] != "#":
        return False
    if start_x is None:
        start_x = x
        start_y = y
    dx, dy = x - start_x, y - start_y
    # m = copy.deepcopy(field)
    visited = [{} for _ in range(h)]
    for red_y in range(h):
        for red_x in range(w):
            if visited[red_y].get(red_x) is None and field[red_y][red_x] == "#":
                # m[red_y][red_x] = "@"
                visited[red_y][red_x] = True
                nx = red_x + dx
                ny = red_y + dy
                if ny >= h or nx >= w or field[ny][nx] != "#" or visited[ny].get(nx) is not None:
                    return False
                # m[ny][nx] = "@"
                visited[ny][nx] = True
    return True



for i in range(h):
    for j in range(w):
        if check(i, j):
            print("YES")
            exit()
print("NO")
0