코딩테스트 연습 스터디 진행중 입니다. ✍✍✍
Notion : https://www.notion.so/1c911ca6572e4513bd8ed091aa508d67
문제
https://www.acmicpc.net/problem/1018
풀이
[나의 풀이]
m,n = map(int,input().split())
a =[list(input()) for _ in range(m)]
board = []
for value in a:
board.append(value)
chess1 = [ 'WBWBWBWB' if i%2 == 0 else 'WBWBWBWB'[::-1] for i in range(8)]
chess2 = chess1[::-1]
cnt_chess1 = 0
cnt_chess2 = 0
ans_cnt_chess1 = 2500
ans_cnt_chess2 = 2500
for i in range(m-7):
for j in range(n-7):
cnt_chess1 = 0
cnt_chess2 = 0
for k in range(8):
for l in range(8):
if board[i+k][j+l] != chess1[k][l]:
cnt_chess1 +=1
if board[i+k][j+l] != chess2[k][l]:
cnt_chess2 +=1
if cnt_chess1 < ans_cnt_chess1:
ans_cnt_chess1 = cnt_chess1
if cnt_chess2 < ans_cnt_chess2:
ans_cnt_chess2 = cnt_chess2
if ans_cnt_chess1 >= ans_cnt_chess2:
print(ans_cnt_chess2)
else:
print(ans_cnt_chess1)
[팀원의 풀이]
from collections import deque
from itertools import *
import sys
import copy
input = sys.stdin.readline
def printboard(board, n) :
for i in range(n) :
print(board[i])
n, m = list(map(int, input().split()))
board = list(list(map(str, input())) for _ in range(n))
def findcolor(board, x, y):
cnt1, cnt2 = 0, 0
for i in range(8):
for j in range(8):
if i == 0 and j == 0:
ic = board[x + i][y + j]
if (i + j) % 2 == 0 and board[x + i][y + j] != ic:
cnt1 += 1
if (i + j) % 2 != 0 and board[x + i][y + j] == ic:
cnt1 += 1
if (i + j) % 2 == 0 and board[x + i][y + j] == ic :
cnt2 += 1
if (i + j) % 2 != 0 and board[x + i][y + j] != ic:
cnt2 += 1
if cnt1 < cnt2 :
return cnt1
else :
return cnt2
def sol(board):
copy_board = copy.deepcopy(board)
min = 2500
for i in range(n):
copy_board[i].pop()
if i + 7 >= n:
break
for j in range(m):
if j + 7 >= m:
break
tmp = findcolor(copy_board,i,j)
if tmp < min :
min = tmp
print(min)
sol(board)
메모
감사합니다.🐥🐥🐥