-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_1018
More file actions
60 lines (50 loc) · 1.5 KB
/
BAEKJOON_1018
File metadata and controls
60 lines (50 loc) · 1.5 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
import java.io.*;
import java.util.*;
public class Main {
static boolean[][] arr;
public static int min =64;
public static void main(String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
arr=new boolean[N][M];
//StringBuilder sb;
for(int i=0; i<N; i++){
String sb =br.readLine();
for(int j=0; j<M; j++){
if(sb.charAt(j)=='W'){
arr[i][j]=true;
}else{
arr[i][j] =false;
}
}
}
int x = N-7; //N =10
int y= M-7;
for(int i=0; i<x; i++){
for(int j=0; j<y; j++){
find(i,j);
}
}
System.out.println(min);
}
public static void find(int x,int y){
int x2 = x+8;
int y2 = y+8;
boolean test =arr[x][y];
int count=0;
for(int i=x; i<x2; i++){
for(int j=y; j<y2; j++){
if(arr[i][j] != test){
count++;
}
test = (!test);
}
test = !test;
}
count= Math.min(count, 64-count);
min = Math.min(min,count);
}
}