Skip to content

Commit

Permalink
Feat: Add solution of #118
Browse files Browse the repository at this point in the history
  • Loading branch information
Dltmd202 committed Jul 5, 2022
1 parent 4cd6b2b commit 231eea1
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/BaekJoon/Dltmd202/1018/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();

public static void main(String[] args) throws IOException {
StringTokenizer st = new StringTokenizer(br.readLine());

int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
char[][] map = new char[n][m];
char[] checker = {'W', 'B'};

for (int i = 0; i < n; i++) {
map[i] = br.readLine().toCharArray();
}

int res = Integer.MAX_VALUE;
for (int i = 0; i <= n - 8; i++) {
for (int j = 0; j <= m - 8; j++) {
res = Math.min(res, check(n, m, map, checker, 0, i, j));
res = Math.min(res, check(n, m, map, checker, 1, i, j));
}
}
System.out.println(res);
}

private static int check(int n, int m, char[][] map, char[] checker, int grad, int sy, int sx) {
int modified = 0;
int turn = grad;
for (int i = sy; i < sy + 8; i++) {
for (int j = sx; j < sx + 8; j++) {
if (checker[turn % 2] != map[i][j]) {
modified++;
}
turn++;
}
turn++;
}
return modified;
}
}

0 comments on commit 231eea1

Please sign in to comment.