-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1018.py
More file actions
34 lines (34 loc) · 1018 Bytes
/
1018.py
File metadata and controls
34 lines (34 loc) · 1018 Bytes
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
n,m=map(int,input().split())
final=[]
output=[input() for _ in range(n)]
for p in range(n-8+1):
for q in range(m-8+1):
cnt1=0
cnt2=0
if output[p][q]=='B':
x='B'
for a in range(8):
for b in range(8):
if output[a+p][b+q]!=x:
cnt1+=1
if output[a+p][b+q]==x:
cnt2+=1
if b!=7 and x=='B':
x='W'
elif b!=7 and x=='W':
x='B'
else:
x='W'
for a in range(8):
for b in range(8):
if output[a+p][b+q]!=x:
cnt1+=1
if output[a+p][b+q]==x:
cnt2+=1
if b!=7 and x=='B':
x='W'
elif b!=7 and x=='W':
x='B'
final.append(min(cnt1,cnt2))
final.sort()
print(final[0])