✔ 풀이를 위한 아이디어
✔ 코드
import sys
N, M = map(int, sys.stdin.readline().split())
chess = [list(sys.stdin.readline()) for _ in range(N)]
cases = []
for i in range(N-7):
start_y = i
for j in range(M-7):
start_x = j
count = 0
# Case1: 짝수면 B, 홀수면 W (BWBWBWBW)
for y in range(start_y, start_y+8):
for x in range(start_x, start_x+8):
if (x+y) % 2 == 0 and chess[y][x] == 'W':
count += 1
elif (x+y) % 2 == 1 and chess[y][x] == 'B':
count += 1
cases.append(count)
count = 0
# Case2: 짝수면 W, 홀수면 B (WBWBWBWB)
for y in range(start_y, start_y+8):
for x in range(start_x, start_x+8):
if (x+y) % 2 == 0 and chess[y][x] == 'B':
count += 1
elif (x+y) % 2 == 1 and chess[y][x] == 'W':
count += 1
cases.append(count)
print(min(cases))
✔ 관련 개념