문제

코드
import java.util.Scanner;
public class q2630 {
static int countW = 0, countB = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
boolean[][] paper = new boolean[N][N];
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
int temp = sc.nextInt();
if(temp == 1) paper[i][j] = true;
}
}
cut(paper, N, 0, 0);
System.out.println(countW + "\n" + countB);
}
public static void cut(boolean[][] paper, int size, int startX, int startY) {
if(size != 1) {
int tempW = 0, tempB = 0;
for(int i=startX; i<startX+size; i++) {
for(int j=startY; j<startY+size; j++) {
if(paper[i][j]) tempB++;
else tempW++;
}
}
if(tempW != 0 && tempB != 0) {
for(int a=0; a<2; a++) {
for(int b=0; b<2; b++) {
cut(paper, size/2, startX + a*(size/2), startY + b*(size/2));
}
}
}
else {
if(tempW == 0) countB++;
else countW++;
return;
}
}
if(size == 1) {
if(paper[startX][startY]) countB++;
else countW++;
return;
}
}
}
가치 있는 정보 공유해주셔서 감사합니다.