結果

問題 No.179 塗り分け
ユーザー IJKTanabeIJKTanabe
提出日時 2019-03-20 20:00:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,604 bytes
コンパイル時間 764 ms
コンパイル使用メモリ 81,660 KB
実行使用メモリ 79,968 KB
最終ジャッジ日時 2023-10-19 04:31:25
合計ジャッジ時間 28,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_16 WA -
testcase_17 WA -
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 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    try:
        H, W = map(int, input('行数 列数 = ? ').split())
    except:
        print('入力に誤りがあります。終了します')
        sys.exit(0)

    cells = []
    while len(cells) < H:
        _input = input(str(len(cells) + 1) + ': = ? ')

        if (len(_input) == W) and (len(_input.replace('#', '').replace('.', '')) == 0):
            cells.append(list(_input.strip()))
        else:
            print('')
            if len(_input) != W:
                print('*** ' + str(W) + '文字で入力してください' + ' ***')
            if len(_input.replace('#', '').replace('.', '')) != 0:
                print('*** \'#\'と\'.\'のみで入力してください ***')
            print('')
    
    cells_tuple = tuple(tuple(i) for i in cells)
    cells = None

    result = []
    for y in range((-H)+1, H):
        for x in range((-W)+1, W):
            result.append(try_paint(cells_tuple, H, W, y, x))
    
    if True in result:
        print('YES')
    else:
        print('NO')



def try_paint(cells, H, W, vecY, vecX):

    _cells = list(list(i) for i in cells)

    #input('vectorY = ' + str(vecY) + ' : vectorX = ' + str(vecX))
    flg = None

    for y in range(0, H):
        for x in range(0, W):
            
            refY = y - vecY
            refX = x - vecX
            trgY = y + vecY
            trgX = x + vecX
            
            #print ('y = ' + str(y) + ': x = ' + str(x) + 'is now \'' + _cells[y][x] + '\'' )

            # 赤色に塗る判定
            if _cells[y][x] == '#':
                if refY in range(0,H) and refX in range(0,W):
                    if _cells[refY][refX] != '#':
                        _cells[y][x] = 'R'
                else: _cells[y][x] = 'R'
            
            #Todo 青色判定も、マイナスインデックスの影響排除
            if _cells[y][x] == 'R':
                if trgY in range(0,H) and trgX in range(0,W):
                    if _cells[trgY][trgX] == '#':
                        _cells[trgY][trgX] = 'B'
                        #print('paint to RED and BLUE')
                        if flg == None: flg = True
                    else:
                        #print('paint to RED but BLUE !!!!!')
                        flg = False
                else:
                    #print('paint to RED but BLUE !!!!!')
                    flg = False

    # for line in _cells:
    #     print(''.join(line))

    return flg

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