結果

問題 No.179 塗り分け
ユーザー nbisconbisco
提出日時 2017-02-24 00:58:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 799 ms / 3,000 ms
コード長 1,226 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 11,012 KB
実行使用メモリ 8,416 KB
最終ジャッジ日時 2023-09-30 20:53:36
合計ジャッジ時間 5,635 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,792 KB
testcase_01 AC 15 ms
7,800 KB
testcase_02 AC 16 ms
7,872 KB
testcase_03 AC 16 ms
7,912 KB
testcase_04 AC 16 ms
7,876 KB
testcase_05 AC 16 ms
7,772 KB
testcase_06 AC 15 ms
7,920 KB
testcase_07 AC 15 ms
8,296 KB
testcase_08 AC 16 ms
8,352 KB
testcase_09 AC 16 ms
8,352 KB
testcase_10 AC 15 ms
8,388 KB
testcase_11 AC 15 ms
8,348 KB
testcase_12 AC 799 ms
8,296 KB
testcase_13 AC 16 ms
7,848 KB
testcase_14 AC 15 ms
7,804 KB
testcase_15 AC 15 ms
7,912 KB
testcase_16 AC 15 ms
7,796 KB
testcase_17 AC 15 ms
7,804 KB
testcase_18 AC 23 ms
8,156 KB
testcase_19 AC 22 ms
8,288 KB
testcase_20 AC 15 ms
8,240 KB
testcase_21 AC 16 ms
8,220 KB
testcase_22 AC 70 ms
8,304 KB
testcase_23 AC 16 ms
8,212 KB
testcase_24 AC 53 ms
8,336 KB
testcase_25 AC 17 ms
8,356 KB
testcase_26 AC 22 ms
8,316 KB
testcase_27 AC 221 ms
8,300 KB
testcase_28 AC 25 ms
8,248 KB
testcase_29 AC 359 ms
8,300 KB
testcase_30 AC 171 ms
8,352 KB
testcase_31 AC 478 ms
8,416 KB
testcase_32 AC 120 ms
8,308 KB
testcase_33 AC 470 ms
8,336 KB
testcase_34 AC 91 ms
8,216 KB
testcase_35 AC 569 ms
8,352 KB
testcase_36 AC 17 ms
7,852 KB
testcase_37 AC 16 ms
7,828 KB
testcase_38 AC 16 ms
7,724 KB
testcase_39 AC 17 ms
7,852 KB
testcase_40 AC 15 ms
7,912 KB
testcase_41 AC 15 ms
7,860 KB
testcase_42 AC 16 ms
7,808 KB
testcase_43 AC 24 ms
7,908 KB
testcase_44 AC 57 ms
7,804 KB
testcase_45 AC 16 ms
7,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def move_ok(_S, H, W, count, diff):
    S = [[_S[i][j] for j in range(W)] for i in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                continue
            elif i+diff[0] < H and j+diff[1] < W \
                and S[i+diff[0]][j+diff[1]] == "#":
                count -= 2
                S[i+diff[0]][j+diff[1]] = "."
    return count == 0

def main():
    H, W = map(int, input().split(" "))
    S = []
    for i in range(H):
        S.append(list(input()))
    start = [-1,-1]
    count = 0
    for i in range(H):
        count += S[i].count("#")
        if start[0] == -1:
            for j in range(W):
                if S[i][j] == "#":
                    start[0] = i
                    start[1] = j
                    break
    if count % 2 != 0:
        print("NO")
        return

    for i in range(H):
        for j in range(W):
            if start[0] == i and start[1] == j:
                continue
            if S[i][j] == ".":
                continue
            diff = (i-start[0], j-start[1])
            if move_ok(S, H, W, count, diff):
                print("YES")
                return
    print("NO")

if __name__ == "__main__":
    main()
0