백준 - 2630 : 색종이 만들기 [자바]

HungAh.log·2021년 8월 19일
0
post-custom-banner
import java.util.*;
import java.io.*;

public class Main {
	static int white, blue;
	static int[][] paper;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int N = Integer.parseInt(br.readLine());
		paper = new int[N][N];
		for (int i = 0; i < N; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine(), " ");
			for (int j = 0; j < N; j++) {
				paper[i][j] = Integer.parseInt(st.nextToken());
			}
		}
		cut(0, 0, N);
        sb.append(white).append("\n").append(blue);
		System.out.println(sb);
		br.close();
	}

	static void cut(int r, int c, int n) {
		int sum = 0;
		for (int i = r; i < r + n; i++) {
			for (int j = c; j < c + n; j++) {
				sum += paper[i][j];
			}
		}
		if (sum == n * n) {
			blue++;
		} else if (sum == 0) {
			white++;
		} else {
			int size = n / 2;
			cut(r, c, size);
			cut(r, c + size, size);
			cut(r + size, c, size);
			cut(r + size, c + size, size);
		}

	}
}
profile
👩🏻‍💻
post-custom-banner

0개의 댓글