結果

問題 No.179 塗り分け
ユーザー yomo3yomo3
提出日時 2020-02-25 21:57:11
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 82 ms / 3,000 ms
コード長 1,174 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 11,132 KB
実行使用メモリ 8,476 KB
最終ジャッジ日時 2023-09-30 21:24:50
合計ジャッジ時間 2,647 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,408 KB
testcase_01 AC 15 ms
8,384 KB
testcase_02 AC 16 ms
8,376 KB
testcase_03 AC 17 ms
8,376 KB
testcase_04 AC 17 ms
8,356 KB
testcase_05 AC 22 ms
8,284 KB
testcase_06 AC 17 ms
8,404 KB
testcase_07 AC 16 ms
8,312 KB
testcase_08 AC 17 ms
8,440 KB
testcase_09 AC 16 ms
8,408 KB
testcase_10 AC 17 ms
8,296 KB
testcase_11 AC 16 ms
8,476 KB
testcase_12 AC 82 ms
8,300 KB
testcase_13 AC 15 ms
8,324 KB
testcase_14 AC 16 ms
8,336 KB
testcase_15 AC 15 ms
8,432 KB
testcase_16 AC 16 ms
8,276 KB
testcase_17 AC 16 ms
8,272 KB
testcase_18 AC 17 ms
8,412 KB
testcase_19 AC 17 ms
8,476 KB
testcase_20 AC 44 ms
8,456 KB
testcase_21 AC 21 ms
8,428 KB
testcase_22 AC 22 ms
8,348 KB
testcase_23 AC 16 ms
8,452 KB
testcase_24 AC 20 ms
8,348 KB
testcase_25 AC 17 ms
8,344 KB
testcase_26 AC 16 ms
8,468 KB
testcase_27 AC 28 ms
8,464 KB
testcase_28 AC 17 ms
8,340 KB
testcase_29 AC 36 ms
8,308 KB
testcase_30 AC 24 ms
8,424 KB
testcase_31 AC 40 ms
8,444 KB
testcase_32 AC 22 ms
8,472 KB
testcase_33 AC 41 ms
8,432 KB
testcase_34 AC 20 ms
8,456 KB
testcase_35 AC 45 ms
8,304 KB
testcase_36 AC 16 ms
8,264 KB
testcase_37 AC 16 ms
8,408 KB
testcase_38 AC 17 ms
8,440 KB
testcase_39 AC 16 ms
8,248 KB
testcase_40 AC 16 ms
8,360 KB
testcase_41 AC 16 ms
8,248 KB
testcase_42 AC 16 ms
8,248 KB
testcase_43 AC 17 ms
8,432 KB
testcase_44 AC 19 ms
8,276 KB
testcase_45 AC 16 ms
8,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import product

H, W = map(int, input().split())
S = [input() for _ in range(H)]

def solve(h0, w0, dh, dw):
    color = [[None] * W for _ in range(H)]
    color[h0][w0] = 'R'
    color[h0 + dh][w0 + dw] = 'B'
    for h, w in product(range(h0, H), range(W)):
        if h == h0 and w <= w0: continue
        if S[h][w] == '#' and color[h][w] == None:
            if h + dh < H and w + dw < W and S[h + dh][
                    w + dw] == '#' and color[h + dh][w + dw] == None:
                color[h][w] = 'R'
                color[h + dh][w + dw] = 'B'
            else:
                return False
    for h, w in product(range(H), range(W)):
        if S[h][w] == '#' and color[h][w] == None:
            return False
    return True

h0 = w0 = -1
for h, w in product(range(H), range(W)):
    if S[h][w] == '#':
        h0, w0 = h, w
        break
else:
    print('NO')
    sys.exit()

yes = False

for h, w in product(range(h0, H), range(W)):
    if h == h0 and w <= w0: continue
    if S[h][w] == '#':
        dh, dw = h - h0, w - w0
        if (solve(h0, w0, dh, dw)):
            yes = True
            break

print('YES' if yes else 'NO')
0