結果

問題 No.179 塗り分け
ユーザー CsTarepandaCsTarepanda
提出日時 2019-04-21 21:28:02
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 1,706 ms / 3,000 ms
コード長 935 bytes
コンパイル時間 434 ms
コンパイル使用メモリ 10,736 KB
実行使用メモリ 8,604 KB
最終ジャッジ日時 2023-07-29 11:40:24
合計ジャッジ時間 12,131 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,500 KB
testcase_01 AC 19 ms
8,372 KB
testcase_02 AC 19 ms
8,352 KB
testcase_03 AC 18 ms
8,464 KB
testcase_04 AC 18 ms
8,512 KB
testcase_05 AC 18 ms
8,356 KB
testcase_06 AC 19 ms
8,504 KB
testcase_07 AC 19 ms
8,488 KB
testcase_08 AC 20 ms
8,432 KB
testcase_09 AC 21 ms
8,436 KB
testcase_10 AC 21 ms
8,408 KB
testcase_11 AC 21 ms
8,504 KB
testcase_12 AC 1,706 ms
8,564 KB
testcase_13 AC 19 ms
8,452 KB
testcase_14 AC 19 ms
8,460 KB
testcase_15 AC 18 ms
8,348 KB
testcase_16 AC 18 ms
8,360 KB
testcase_17 AC 18 ms
8,376 KB
testcase_18 AC 40 ms
8,468 KB
testcase_19 AC 38 ms
8,556 KB
testcase_20 AC 20 ms
8,384 KB
testcase_21 AC 19 ms
8,368 KB
testcase_22 AC 219 ms
8,584 KB
testcase_23 AC 21 ms
8,460 KB
testcase_24 AC 152 ms
8,464 KB
testcase_25 AC 26 ms
8,564 KB
testcase_26 AC 40 ms
8,552 KB
testcase_27 AC 623 ms
8,380 KB
testcase_28 AC 40 ms
8,468 KB
testcase_29 AC 943 ms
8,460 KB
testcase_30 AC 382 ms
8,576 KB
testcase_31 AC 1,151 ms
8,604 KB
testcase_32 AC 251 ms
8,468 KB
testcase_33 AC 1,173 ms
8,572 KB
testcase_34 AC 184 ms
8,468 KB
testcase_35 AC 1,359 ms
8,568 KB
testcase_36 AC 19 ms
8,448 KB
testcase_37 AC 19 ms
8,512 KB
testcase_38 AC 19 ms
8,500 KB
testcase_39 AC 19 ms
8,352 KB
testcase_40 AC 19 ms
8,512 KB
testcase_41 AC 19 ms
8,380 KB
testcase_42 AC 19 ms
8,452 KB
testcase_43 AC 39 ms
8,520 KB
testcase_44 AC 130 ms
8,528 KB
testcase_45 AC 23 ms
8,452 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)
    for red_y in range(h):
        for red_x in range(w):
            if m[red_y][red_x] == "#":
                m[red_y][red_x] = "@"
                nx = red_x + dx
                ny = red_y + dy
                if ny >= h or nx >= w or m[ny][nx] != "#":
                    return False
                m[ny][nx] = "@"
    return True



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