https://www.acmicpc.net/problem/1018
(입력 및 선언)
(색칠해야 하는 칸 찾기)
WBWBWBWB
BWBWBWBW
WBWBWBWB
BWBBBWBW
WBWBWBWB
BWBWBWBW
WBWBWBWB
BWBWBWBW
WBWBWBWB
BWBWBWBW
bold된 부분의 값이 모두 a+b가 짝수인 부분이다.
n, m = map(int, input().split())
board = []
ans = []
for _ in range(n) :
board.append(list(map(str, input())))
for i in range(n-7) :
for j in range(m-7) :
draw1 = 0
draw2 = 0
for a in range(i, i+8) :
for b in range(j, j+8) :
if (a+b) % 2 == 0 :
if board[a][b] == 'W' :
draw1 += 1
elif board[a][b] == 'B' :
draw2 += 1
else :
if board[a][b] == 'B' :
draw1 += 1
elif board[a][b] == 'W' :
draw2 += 1
ans.append(draw1)
ans.append(draw2)
print(min(ans))