結果

問題 No.179 塗り分け
ユーザー hang_hang_clnhang_hang_cln
提出日時 2018-06-09 10:59:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,125 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 8,384 KB
最終ジャッジ日時 2023-09-13 01:41:38
合計ジャッジ時間 7,187 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 RE -
testcase_40 WA -
testcase_41 RE -
testcase_42 RE -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int,input().split())
    
field = []
for h in range(H):
    field.append(list(input()))

def painting(dx, dy,black_cnt):
    # ある平行移動量で塗れるか判定
    paintCnt = 0 # 赤または青で塗った枚数
    canPaintByThiWay = True # この平行移動量で塗り分け可能か
    paint = [[0 for w in range(W)] for h in range(H)] # 0:塗ってない 1:赤 2:青
    for h in range(H):
        for w in range(W):
            if field[h][w] == '#' and paint[h][w] == 0: # 赤で塗ることができる
                paint[h][w] = 1 # 赤で塗る
                paintCnt += 1
                # 平行移動先に青でも塗ってみる
                if h+dy >= H or w+dx >= W: # フィールドの外に移動しようとしていたら
                    return False
                elif field[h+dy][w+dx] == '#' and paint[h+dy][w+dx] == 0: # 青で塗ることができる
                    paint[h+dy][w+dx] = 2 # 青で塗る
                    paintCnt += 1
                else: # 青で塗ることが出来ない = 失敗
                    return False # この平行移動量ではむり
            else: # 赤で塗ることができない = 失敗とは限らない
                if paint[h][w] == 2: # 青ですでに塗られていたら
                    return False # この平行移動量ではむり

            if paintCnt == black_cnt:
                return True

def check():
    black_cnt = 0
    for h in range(H):
        for w in range(W):
            #print(field[h][w])
            if field[h][w] == '#':
                black_cnt += 1
                
    else:
        # 平行移動量を決める
        for dx in range(W):
            for dy in range(H):
                if dx == 0 and dy == 0:
                    continue
                
                if painting(dx,dy,black_cnt):
                    canPaint = True
                    break
                else:
                    canPaint = False
            if canPaint:
                break
        
        return canPaint

if check():
    print('Yes')
else:
    print('No')
0