Skip to content

Instantly share code, notes, and snippets.

@surinoel
Last active July 25, 2019 10:05
Show Gist options
  • Save surinoel/0544efa212b8bcdc6b1e6d72ea1fca6d to your computer and use it in GitHub Desktop.
Save surinoel/0544efa212b8bcdc6b1e6d72ea1fca6d to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int mat[128][128];
void go(int n, int x, int y, int &b, int &w) {
if (n == 1) {
if (mat[x][y] == 1) b += 1;
else w += 1;
return;
}
bool ok = true;
int target = mat[x][y];
for (int i = x; i < x + n; i++) {
for (int j = y; j < y + n; j++) {
if (target != mat[i][j]) {
ok = false;
}
}
}
if (ok) {
if (target == 1) b += 1;
else w += 1;
}
else {
go(n / 2, x, y, b, w);
go(n / 2, x + n / 2, y, b, w);
go(n / 2, x, y + n / 2, b, w);
go(n / 2, x + n / 2, y + n / 2, b, w);
}
return;
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> mat[i][j];
}
}
int b = 0, w = 0;
go(n, 0, 0, b, w);
cout << w << '\n' << b << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment