Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
916 B
2
Indexable
Never
#include <iostream>
using namespace std;

int a[1000][1000];
int n;
int count_t, count_x;

bool check(int x, int y, int s) {
	int temp = a[x][y];
	for (int i = x; i < x + s; i++) {
		for (int j = y; j < y + s; j++) {
			if (a[i][j] != temp) {
				return false;
			}
		}
	}
	return true;
}

void sub(int x, int y, int s) {
	if (check(x, y, s)) {
		if (a[x][y] == 0)
			count_t++;
		if (a[x][y] == 1)
			count_x++;
		return;
	}

	else {
		sub(x, y, s / 2);
		sub(x , y + s / 2, s / 2);
		sub(x + s / 2, y, s / 2);
		sub(x + s / 2, y + s / 2, s / 2);
	}
}

int main() {
	int t;
	cin >> t;
	for (int tc = 1; tc <= t; tc++) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> a[i][j];
			}
		}

		count_t = 0;
		count_x = 0;

		sub(0, 0, n);

		cout << "Case #" << tc << endl;
		cout << count_t << " " << count_x << endl;
	}

}