[BOJ] 1018번 체스판 다시 칠하기

chowisely·2021년 1월 6일
0

BOJ

목록 보기
53/70

문제 바로가기

#include <iostream>
#include <cstdio>
#include <limits>
using namespace std;

#define INF 987654321

static char B[8][9] = {
  "BWBWBWBW",
  "WBWBWBWB",
  "BWBWBWBW",
  "WBWBWBWB",
  "BWBWBWBW",
  "WBWBWBWB",
  "BWBWBWBW",
  "WBWBWBWB",
};

static char W[8][9] = {
  "WBWBWBWB",
  "BWBWBWBW",
  "WBWBWBWB",
  "BWBWBWBW",
  "WBWBWBWB",
  "BWBWBWBW",
  "WBWBWBWB",
  "BWBWBWBW",
};

int main() {
  std::ios::sync_with_stdio(false);
  int N, M;
  int cnt, minval = INF;
  string arr[50];
  cin >> N >> M;

  for(int i = 0; i < N; i++)
      cin >> arr[i];

  for(int i = 0; i < N - 7; i++) {
    for(int j = 0; j < M - 7; j++) {
      // starting from B
      cnt = 0;
      for(int x = 0; x < 8; x++) {
        for(int y = 0; y < 8; y++) {
          if(arr[i + x][j + y] != B[x][y])
            cnt++;
        }
      }
      minval = min(minval, cnt);

      // starting from W
      cnt = 0;
      for(int x = 0; x < 8; x++) {
        for(int y = 0; y < 8; y++) {
          if(arr[i + x][j + y] != W[x][y])
            cnt++;
        }
      }
      minval = min(minval, cnt);
    }
  }
  printf("%d", minval);
}

0개의 댓글