-
Notifications
You must be signed in to change notification settings - Fork 0
/
1018.py
46 lines (41 loc) · 904 Bytes
/
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
import sys
N,M=map(int,sys.stdin.readline().split())
board=[['0']*M for i in range(N)]
for i in range(N):
board[i]=list(sys.stdin.readline().rstrip())
board_list = []
for i in range(N-8+1):
for j in range(M-8+1):
new_board=[['0']*M for i in range(N)]
for a in range(8):
for b in range(8):
new_board[a][b]=board[i+a][j+b]
board_list.append(new_board)
graph1=['BWBWBWBW',
'WBWBWBWB',
'BWBWBWBW',
'WBWBWBWB',
'BWBWBWBW',
'WBWBWBWB',
'BWBWBWBW',
'WBWBWBWB']
graph2=['WBWBWBWB',
'BWBWBWBW',
'WBWBWBWB',
'BWBWBWBW',
'WBWBWBWB',
'BWBWBWBW',
'WBWBWBWB',
'BWBWBWBW']
temp=9999
for b in board_list:
count1=0
count2=0
for i in range(8):
for j in range(8):
if b[i][j]!=graph1[i][j]:
count1+=1
if b[i][j]!=graph2[i][j]:
count2+=1
temp=min(temp,count1,count2)
print(temp)