結果

問題 No.179 塗り分け
ユーザー pajannatpajannat
提出日時 2021-04-14 00:12:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,404 ms / 3,000 ms
コード長 2,281 bytes
コンパイル時間 1,142 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 88,056 KB
最終ジャッジ日時 2023-09-12 14:55:16
合計ジャッジ時間 35,170 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,464 KB
testcase_01 AC 87 ms
71,820 KB
testcase_02 AC 101 ms
77,392 KB
testcase_03 AC 86 ms
71,804 KB
testcase_04 AC 103 ms
77,112 KB
testcase_05 AC 249 ms
78,392 KB
testcase_06 AC 181 ms
78,408 KB
testcase_07 AC 1,115 ms
87,680 KB
testcase_08 AC 1,069 ms
87,236 KB
testcase_09 AC 1,064 ms
87,344 KB
testcase_10 AC 1,312 ms
87,576 KB
testcase_11 AC 1,155 ms
86,312 KB
testcase_12 AC 1,153 ms
86,076 KB
testcase_13 AC 107 ms
77,708 KB
testcase_14 AC 107 ms
77,664 KB
testcase_15 AC 88 ms
71,656 KB
testcase_16 AC 88 ms
71,716 KB
testcase_17 AC 86 ms
71,556 KB
testcase_18 AC 1,310 ms
87,580 KB
testcase_19 AC 1,111 ms
86,708 KB
testcase_20 AC 1,237 ms
87,032 KB
testcase_21 AC 1,088 ms
87,400 KB
testcase_22 AC 1,287 ms
87,772 KB
testcase_23 AC 1,230 ms
87,380 KB
testcase_24 AC 1,106 ms
87,244 KB
testcase_25 AC 1,123 ms
87,240 KB
testcase_26 AC 1,158 ms
87,480 KB
testcase_27 AC 1,229 ms
87,400 KB
testcase_28 AC 1,310 ms
87,296 KB
testcase_29 AC 1,396 ms
88,056 KB
testcase_30 AC 1,404 ms
87,664 KB
testcase_31 AC 1,313 ms
87,612 KB
testcase_32 AC 1,380 ms
87,900 KB
testcase_33 AC 1,317 ms
87,800 KB
testcase_34 AC 1,404 ms
87,672 KB
testcase_35 AC 1,340 ms
87,484 KB
testcase_36 AC 88 ms
71,628 KB
testcase_37 AC 89 ms
71,828 KB
testcase_38 AC 89 ms
71,652 KB
testcase_39 AC 88 ms
71,580 KB
testcase_40 AC 96 ms
76,552 KB
testcase_41 AC 88 ms
71,564 KB
testcase_42 AC 90 ms
71,584 KB
testcase_43 AC 161 ms
78,196 KB
testcase_44 AC 265 ms
78,624 KB
testcase_45 AC 128 ms
77,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    # 入力行数が多いとき。
    from sys import stdin
    # 数値として入力一つを読み込み
    H, W = map(int, stdin.readline().rstrip().split())
    d = [stdin.readline().rstrip() for i in range(H)]

    # 平行移動が成功したかどうかを判断するフラグ
    success_flg = False
    blue = [[False for w in range(W)] for h in range(H)]
    # リストblueの値を渡す
    import copy
    blue_tmp = copy.deepcopy(blue)

    # 平行移動パターンの全探索
    for i in range(H):
        for j in range(-W+1,W):
            # 移動なしパターンを除外
            if i == 0 and j == 0:
                pass
            # 左方向への移動を除外
            elif i == 0 and j < 0:
                pass
            else:
                # すべてのマスを平行移動する
                # 最後までflg=TrueならYESを出力
                flg = True
                # マスの色を初期化
                blue_tmp = copy.deepcopy(blue)
                for h in range(H):
                    for w in range(W):
                        # マスが白色または青色の場合は判定しない
                        if d[h][w] == "." or blue_tmp[h][w]:
                            pass
                        # 平行移動して範囲内の場合に判定
                        elif h+i<H and h+i>=0 and w+j<W and w+j>=0:
                            if d[h][w] == "#" and d[h+i][w+j] == "#":
                                blue_tmp[h+i][w+j] = True
                            # 平行移動先のマスが"#"でない場合はNG
                            else:
                                flg = False
                        # 平行移動して範囲外に出る場合はNG
                        else:
                            flg = False
                # すべてのマスを平行移動させて最後までNGなし
                # 1マス以上青マスがある
                import itertools
                if flg and (True in itertools.chain.from_iterable(blue_tmp)):
                    success_flg = True                   
                        
    if success_flg:
        print("YES")
    else:
        print("NO")

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