-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ2630.java
More file actions
60 lines (49 loc) · 1.52 KB
/
BOJ2630.java
File metadata and controls
60 lines (49 loc) · 1.52 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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ2630 {
static int w = 0;
static int b = 0;
static int[][] graph;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
graph = new int[N][N];
for(int i = 0; i < N; i++){
StringTokenizer st = new StringTokenizer(br.readLine());
for(int j = 0; j < N; j++){
graph[i][j] = Integer.parseInt(st.nextToken());
}
}
recur(0, 0, N);
System.out.println(w);
System.out.println(b);
}
static void recur(int row, int col, int size){
if(colorCheck(row, col, size)){
if(graph[row][col] == 0){
w++;
}else{
b++;
}
return;
}
int newsize = size / 2;
recur(row, col, newsize);
recur(row + newsize, col, newsize);
recur(row, col + newsize, newsize);
recur(row + newsize, col + newsize, newsize);
}
public static boolean colorCheck(int row, int col, int size) {
int color = graph[row][col];
for(int i = row; i < row + size; i++) {
for(int j = col; j < col + size; j++) {
if(graph[i][j] != color) {
return false;
}
}
}
return true;
}
}