백준 (c++) 1018 체스판 다시 칠하기
백준1018번 바로가기
#include <iostream>
using namespace std;
char board[50][50];
int chk_board(int i, int j)
{
if ((board[i][j] != board[i][j + 1]) && (board[i][j] != board[i + 1][j]))
return 0;
else
return 1;
}
int main(void)
{
int n;
int m;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> board[i][j];
}
}
int min_paint = n * m;
for (int i = 0; i <= n - 8; i++)
{
for (int j = 0; j <= m - 8; j++)
{
for (int start_color = 0; start_color < 2; start_color++)
{
int cnt = 0;
for (int x = i; x < i + 8; x++)
{
for (int y = j; y < j + 8; y++)
{
char target_color = ((x + y + start_color) % 2 == 0) ? 'B' : 'W';
if (board[x][y] != target_color)
cnt++;
}
}
if (min_paint > cnt)
{
min_paint = cnt;
}
}
}
}
cout << min_paint << endl;
return 0;
}