結果

問題 No.179 塗り分け
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-04-28 20:25:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 196 ms / 3,000 ms
コード長 1,051 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 86,680 KB
実行使用メモリ 77,524 KB
最終ジャッジ日時 2023-09-30 20:49:26
合計ジャッジ時間 6,778 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,060 KB
testcase_01 AC 71 ms
71,144 KB
testcase_02 AC 71 ms
71,136 KB
testcase_03 AC 70 ms
70,800 KB
testcase_04 AC 72 ms
70,996 KB
testcase_05 AC 71 ms
70,724 KB
testcase_06 AC 91 ms
76,252 KB
testcase_07 AC 71 ms
70,992 KB
testcase_08 AC 133 ms
77,284 KB
testcase_09 AC 132 ms
77,072 KB
testcase_10 AC 109 ms
77,068 KB
testcase_11 AC 107 ms
76,904 KB
testcase_12 AC 141 ms
77,192 KB
testcase_13 AC 72 ms
71,080 KB
testcase_14 AC 76 ms
75,112 KB
testcase_15 AC 70 ms
71,148 KB
testcase_16 AC 71 ms
71,100 KB
testcase_17 AC 71 ms
70,848 KB
testcase_18 AC 111 ms
76,820 KB
testcase_19 AC 111 ms
76,964 KB
testcase_20 AC 71 ms
71,192 KB
testcase_21 AC 71 ms
71,180 KB
testcase_22 AC 196 ms
77,296 KB
testcase_23 AC 112 ms
77,196 KB
testcase_24 AC 137 ms
77,076 KB
testcase_25 AC 113 ms
77,060 KB
testcase_26 AC 115 ms
77,224 KB
testcase_27 AC 132 ms
77,028 KB
testcase_28 AC 115 ms
76,904 KB
testcase_29 AC 152 ms
77,256 KB
testcase_30 AC 125 ms
77,032 KB
testcase_31 AC 135 ms
77,036 KB
testcase_32 AC 128 ms
77,404 KB
testcase_33 AC 150 ms
77,508 KB
testcase_34 AC 121 ms
77,368 KB
testcase_35 AC 147 ms
77,524 KB
testcase_36 AC 70 ms
70,916 KB
testcase_37 AC 71 ms
71,188 KB
testcase_38 AC 70 ms
71,036 KB
testcase_39 AC 71 ms
71,100 KB
testcase_40 AC 76 ms
71,060 KB
testcase_41 AC 69 ms
70,992 KB
testcase_42 AC 72 ms
70,708 KB
testcase_43 AC 85 ms
76,248 KB
testcase_44 AC 104 ms
77,440 KB
testcase_45 AC 81 ms
75,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def inside(x, y):
    return 0 <= x < H and 0 <= y < W

def move(h, w):
    c = [[-1] * W for i in range(H)]
    for i in range(H):
        for j in range(W):
            # まだ塗られていない黒マスが見つかったら
            if s[i][j] == '#' and c[i][j] == -1:
                # このマスを赤に塗る
                c[i][j] = 0
                # 対応する黒マスがなければやめる
                ni = i + h; nj = j + w
                if not inside(ni, nj):
                    return False
                if s[ni][nj] != '#':
                    return False
                # 対応するマスを青に
                c[ni][nj] = 1

    return True


H, W = map(int, input().split())
s = []
black = 0
for i in range(H):
    s.append(list(input()))
    black += s[i].count('#')

if black == 0 or black & 1:
    print("NO")
    exit()

for h in range(-H, H):
    for w in range(-W, W):
        if h == w == 0:
            continue
        if move(h, w):
            print("YES")
            exit()
print("NO")
0