-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path체스판 다시 칠하기.cc
52 lines (42 loc) · 1.18 KB
/
체스판 다시 칠하기.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <algorithm>
using namespace std;
void ans(){
int N, M;
char matrix[51][51];
cin >> N >> M;
for(int i = 0; i < N; i++){
string str;
cin >> str;
for(int j = 0; j < M; j++)
matrix[i][j] = str[j];
}
int ans = 10000;
for (int i = 0; i <= N - 8; ++i) {
for (int j = 0; j <= M - 8; ++j) {
int count1 = 0;
int count2 = 0;
for (int x = 0; x < 8; ++x) {
for (int y = 0; y < 8; ++y) {
char expectedChar = ((x + y) % 2 == 0) ? 'B' : 'W';
if (matrix[i + x][j + y] != expectedChar) {
count1++;
}
expectedChar = ((x + y) % 2 == 0) ? 'W' : 'B';
if (matrix[i + x][j + y] != expectedChar) {
count2++;
}
}
}
ans = min(ans, min(count1, count2));
}
}
cout << ans;
}
int main(){
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(false);
ans();
return 0;
}