-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOJ_1018.py
49 lines (35 loc) · 905 Bytes
/
BOJ_1018.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 백준 1018 체스판 다시 칠하기
# 21.01.17
import sys
def compare(row, col):
global black, white, graph
bCnt = 0
wCnt = 0
for i in range(8):
for j in range(8):
if black[i][j] != graph[row + i][col + j]:
bCnt += 1
if white[i][j] != graph[row + i][col + j]:
wCnt += 1
return min(bCnt, wCnt)
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(n):
graph[i] = list((sys.stdin.readline().rstrip()))
b = list('BWBWBWBW')
w = list('WBWBWBWB')
black = [[] for _ in range(8)]
white = [[] for _ in range(8)]
for i in range(8):
if i % 2 == 0:
black[i] = b
white[i] = w
else:
black[i] = w
white[i] = b
ans = 65
ans = min(ans, compare(0,0))
for i in range(n - 7):
for j in range(m - 7):
ans = min(ans, compare(i, j))
print(ans)