Skip to content

Commit ef201cd

Browse files
committed
[BOJ] 체스판 다시 칠하기 / 실버4 / 30분
https://www.acmicpc.net/problem/1018
1 parent a94e7af commit ef201cd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
n, m = map(int, input().split())
2+
3+
mtr = []
4+
cnt = []
5+
for i in range(n):
6+
mtr.append(input())
7+
8+
for a in range(n - 7):
9+
for b in range(m - 7): # 8*8로 자르기 위해, -7해준다
10+
w_index = 0 # 흰색으로 시작
11+
b_index = 0 # 검은색으로 시작
12+
for i in range(a, a + 8): # 시작지점
13+
for j in range(b, b + 8): # 시작지점
14+
if (i + j) % 2 == 0: # 짝수인 경우
15+
if mtr[i][j] != 'W': # W가 아니면, 즉 B이면
16+
w_index += 1 # W로 칠하는 갯수
17+
else: # W일 때
18+
b_index += 1 # B로 칠하는 갯수
19+
else: # 홀수인 경우
20+
if mtr[i][j] != 'W': # W가 아니면, 즉 B이면
21+
b_index += 1 # B로 칠하는 갯수
22+
else:
23+
w_index += 1 # W로 칠하는 갯수
24+
25+
cnt.append(w_index) # W로 시작할 때 경우의 수
26+
cnt.append(b_index) # B로 시작할 때 경우의 수
27+
print(min(cnt))

0 commit comments

Comments
 (0)