[브루트 포스] 체스판 다시 칠하기
2021. 5. 30. 23:14ㆍ백준
이 문제를 풀 당시에 매사가 귀찮아서 진짜 무식하게 풀었다 ㅠ
from sys import stdin
[n, m] = list(map(int, stdin.readline().split(" ")))
WHITE_ROW = list("WBWBWBWB")
BLACK_ROW = list("BWBWBWBW")
matrix = []
for i in range(n):
matrix.append(input())
def check_chess_row(row: str, is_white: bool):
# print(row)
diff_point = 0
check_row = is_white and WHITE_ROW or BLACK_ROW
for i in range(8):
if list(row)[i] != check_row[i]:
diff_point = diff_point + 1
return diff_point
res = []
for j in range(m - 7):
for k in range(n - 7):
count = 0
count = count + check_chess_row(matrix[k][j:j+8], True)
count = count + check_chess_row(matrix[k + 1][j:j+8], False)
count = count + check_chess_row(matrix[k + 2][j:j+8], True)
count = count + check_chess_row(matrix[k + 3][j:j+8], False)
count = count + check_chess_row(matrix[k + 4][j:j+8], True)
count = count + check_chess_row(matrix[k + 5][j:j+8], False)
count = count + check_chess_row(matrix[k + 6][j:j+8], True)
count = count + check_chess_row(matrix[k + 7][j:j+8], False)
# print(count)
res.append(count)
for k in range(n - 7):
count = 0
count = count + check_chess_row(matrix[k][j:j+8], False)
count = count + check_chess_row(matrix[k + 1][j:j+8], True)
count = count + check_chess_row(matrix[k + 2][j:j+8], False)
count = count + check_chess_row(matrix[k + 3][j:j+8], True)
count = count + check_chess_row(matrix[k + 4][j:j+8], False)
count = count + check_chess_row(matrix[k + 5][j:j+8], True)
count = count + check_chess_row(matrix[k + 6][j:j+8], False)
count = count + check_chess_row(matrix[k + 7][j:j+8], True)
# print(count)
res.append(count)
print(min(res))