https://www.acmicpc.net/problem/1018
25.02.13 풀이
import sys
sys.stdin = open('solve.txt')
input = sys.stdin.readline
N,M = map(int, input().split())
board = [list(input().strip()) for _ in range(N)] # strip을 통해 \n 을 없앤다.
# 부분집합 체크하는 함수
def check_board(s_y,s_x,firstcolor):
count = 0
for y in range(s_y, s_y + 8):
for x in range(s_x, s_x + 8):
if (x+y) % 2 == 0:
if board[y][x] != firstcolor: # 짝수칸이 첫번째 색깔과 다를 경우 다시 색칠
count += 1
elif (x+y) % 2 == 1:
if board[y][x] == firstcolor: # 홀수칸이 첫번째 색깔가 같을 경우 다시 색칠
count += 1
return count # 횟수를 반환
#시작점에 따라 부분 집합
min_count = 99999999999
for s_y in range(N-7):
for s_x in range(N-7):
first_color = board[s_y][s_x]
min_count = min(min_count, check_board(s_y,s_x,first_color))
print(min_count)
무언가 내가 틀린 부분이 있다......
'Baekjoon' 카테고리의 다른 글
2164. 카드 2 (0) | 2025.02.19 |
---|---|
18258. 큐 2 (0) | 2025.02.19 |
1157. 단어 공부 (0) | 2025.02.19 |
21862. 사각형 그리기 게임 (4) | 2025.02.17 |
4949. 균형 잡힌 세상 (0) | 2025.02.14 |