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()