|
| 1 | +import java.io.BufferedReader; |
| 2 | +import java.io.InputStreamReader; |
| 3 | +import java.io.IOException; |
| 4 | +import java.util.Collection; |
| 5 | +import java.util.Collections; |
| 6 | +import java.util.PriorityQueue; |
| 7 | +import java.util.StringTokenizer; |
| 8 | + |
| 9 | +public class Main { |
| 10 | + |
| 11 | + static int arr[][]; |
| 12 | + static int answerZero; |
| 13 | + static int answerOne; |
| 14 | + public static void main(String[] args) throws IOException { |
| 15 | + |
| 16 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 17 | + |
| 18 | + StringTokenizer st; |
| 19 | + int N = Integer.parseInt(br.readLine()); |
| 20 | + |
| 21 | + arr = new int[N+1][N+1]; |
| 22 | + |
| 23 | + for(int i =1; i<=N; i++) { |
| 24 | + st= new StringTokenizer(br.readLine()); |
| 25 | + for(int j =1; j<=N; j++) { |
| 26 | + arr[i][j] = Integer.parseInt(st.nextToken()); |
| 27 | + } |
| 28 | + } |
| 29 | + answerOne =0; |
| 30 | + answerZero =0; |
| 31 | + |
| 32 | + func(1,1, N); |
| 33 | + |
| 34 | + System.out.println(answerZero); |
| 35 | + System.out.println(answerOne); |
| 36 | + } |
| 37 | + |
| 38 | + static void func(int xIndex, int yIndex ,int length) { |
| 39 | + |
| 40 | + if(check(xIndex, xIndex+ length-1,yIndex,yIndex+ length-1 )) { |
| 41 | + if(arr[xIndex][yIndex]==0) { |
| 42 | + answerZero++; |
| 43 | + } |
| 44 | + else { |
| 45 | + answerOne++; |
| 46 | + } |
| 47 | + } |
| 48 | + else { |
| 49 | + func(xIndex + length/2, yIndex, length/2); |
| 50 | + func(xIndex, yIndex+length/2, length/2); |
| 51 | + func(xIndex, yIndex, length/2); |
| 52 | + func(xIndex+length/2, yIndex+length/2, length/2); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + |
| 57 | + static boolean check(int startX, int endX, int startY, int endY) { |
| 58 | + |
| 59 | + int zero = 0; |
| 60 | + int one = 0; |
| 61 | + for(int i = startX; i<=endX; i++) { |
| 62 | + for(int j = startY; j<=endY; j++) { |
| 63 | + if(arr[i][j] == 0) { |
| 64 | + if(one == 0 ){ |
| 65 | + zero++; |
| 66 | + } |
| 67 | + else |
| 68 | + return false; |
| 69 | + } |
| 70 | + else if(arr[i][j] == 1) { |
| 71 | + if(zero ==0) { |
| 72 | + one ++; |
| 73 | + } |
| 74 | + else |
| 75 | + return false; |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + return true; |
| 80 | + } |
| 81 | +} |
0 commit comments