結果

問題 No.179 塗り分け
ユーザー hang_hang_clnhang_hang_cln
提出日時 2018-06-09 11:07:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,210 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 8,432 KB
最終ジャッジ日時 2023-09-13 01:42:23
合計ジャッジ時間 6,414 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,408 KB
testcase_01 AC 16 ms
8,364 KB
testcase_02 AC 16 ms
8,328 KB
testcase_03 AC 16 ms
8,208 KB
testcase_04 AC 16 ms
8,296 KB
testcase_05 AC 40 ms
8,252 KB
testcase_06 AC 16 ms
8,236 KB
testcase_07 WA -
testcase_08 AC 207 ms
8,308 KB
testcase_09 WA -
testcase_10 AC 17 ms
8,364 KB
testcase_11 AC 17 ms
8,360 KB
testcase_12 AC 216 ms
8,224 KB
testcase_13 AC 16 ms
8,252 KB
testcase_14 AC 17 ms
8,188 KB
testcase_15 AC 15 ms
8,264 KB
testcase_16 AC 15 ms
8,224 KB
testcase_17 AC 15 ms
8,328 KB
testcase_18 AC 27 ms
8,288 KB
testcase_19 AC 29 ms
8,312 KB
testcase_20 AC 213 ms
8,416 KB
testcase_21 AC 300 ms
8,236 KB
testcase_22 AC 568 ms
8,240 KB
testcase_23 AC 18 ms
8,292 KB
testcase_24 AC 220 ms
8,360 KB
testcase_25 AC 104 ms
8,260 KB
testcase_26 WA -
testcase_27 AC 214 ms
8,256 KB
testcase_28 WA -
testcase_29 AC 213 ms
8,304 KB
testcase_30 WA -
testcase_31 AC 213 ms
8,432 KB
testcase_32 AC 96 ms
8,296 KB
testcase_33 AC 211 ms
8,236 KB
testcase_34 WA -
testcase_35 AC 211 ms
8,280 KB
testcase_36 AC 15 ms
8,372 KB
testcase_37 AC 16 ms
8,192 KB
testcase_38 AC 16 ms
8,224 KB
testcase_39 AC 16 ms
8,324 KB
testcase_40 AC 16 ms
8,288 KB
testcase_41 AC 17 ms
8,216 KB
testcase_42 AC 16 ms
8,328 KB
testcase_43 AC 20 ms
8,276 KB
testcase_44 AC 41 ms
8,244 KB
testcase_45 AC 16 ms
8,312 KB
権限があれば一括ダウンロードができます

ソースコード

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, 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[0] += 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] += 1
                else: # 青で塗ることが出来ない = 失敗
                    return False # この平行移動量ではむり
            #else: # 赤で塗ることができない = 失敗とは限らない
            #    if paint[h][w] == 2: # 青ですでに塗られていたら
            #        return False # この平行移動量ではむり

            if paintCnt[0]==paintCnt[1] and sum(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:
                    canPaint = False
                    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