-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1018.java
More file actions
69 lines (57 loc) ยท 1.75 KB
/
_1018.java
File metadata and controls
69 lines (57 loc) ยท 1.75 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package backjoon;
// https://www.acmicpc.net/problem/1018
// ์ฒด์คํ ๋ค์ ์น ํ๊ธฐ
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class _1018 {
public static boolean[][] arr;
public static int min = 64; //8*8ํ์ด๋ฏ๋ก ๊ฐ์ฅ ๋ง์ด ์น ํ ์ ์๋ ์ต๋๊ฐ
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// memory 11840 runtime 84
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
arr = new boolean[N][M];
// ๋ฐฐ์ด ์์ฑ
for (int i = 0; i < N; i++) {
String str = br.readLine();
for (int j = 0; j < M; j++) {
// ํฐ์์ผ๋ true
if (str.charAt(j) == 'W') {
arr[i][j] = true;
}
// ๊ฒ์ ์์ผ๋ false
else {
arr[i][j] = false;
}
}
}
// ๋์งธ์ค๋ถํฐ ์์
for (int i = 0; i < N - 7; i++) {
for (int j = 0; j < M - 7; j++) {
findMin(i, j);
}
}
System.out.println(min);
}
public static void findMin(int x, int y) {
int count = 0;
boolean color_yn = arr[x][y]; // ์ฒซ ๋ฒ์งธ ์นธ์ ์
for (int i = x; i < x + 8; i++) {
for (int j = y; j < y + 8; j++) {
// ์ฌ๋ฐ๋ฅธ ์์ด ์๋๊ฒฝ์ฐ ์์ ๋ฐ๊ฟ์ค์ผํ๋ฏ๋ก count 1 ์ฆ๊ฐ
if (arr[i][j] != color_yn) {
count++;
}
// ๋ค์ ์นธ์ ๋ฐ๋์์ผ๋ก ๋ณ๊ฒฝ
color_yn = (!color_yn);
}
color_yn = !color_yn;
}
count = Math.min(count, 64 - count);
min = Math.min(min, count);
}
}