結果
| 問題 | 
                            No.179 塗り分け
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-03-20 20:04:26 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,674 bytes | 
| コンパイル時間 | 212 ms | 
| コンパイル使用メモリ | 81,868 KB | 
| 実行使用メモリ | 80,256 KB | 
| 最終ジャッジ日時 | 2024-09-19 00:48:40 | 
| 合計ジャッジ時間 | 27,487 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 WA * 1 | 
| other | AC * 34 WA * 6 | 
ソースコード
import sys
def main():
    try:
        #H, W = map(int, input('行数 列数 = ? ').split())
        H, W = map(int, input().split())
    except:
        print('入力に誤りがあります。終了します')
        sys.exit(0)
    cells = []
    while len(cells) < H:
        #_input = input(str(len(cells) + 1) + ': = ? ')
        _input = input()
        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()