Skip to content

Instantly share code, notes, and snippets.

@HyeonWooKim
Created November 28, 2016 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HyeonWooKim/6ee612b6b80018a89c042372a611cc48 to your computer and use it in GitHub Desktop.
Save HyeonWooKim/6ee612b6b80018a89c042372a611cc48 to your computer and use it in GitHub Desktop.
BOJ 1780
#include <iostream>
#include <cstdio>
using namespace std;
int w[2222][2222],d[3];
void dfs(int x, int y, int k)
{
bool f = true;
int cmp = w[x][y];
for (int i = x; i < x + k && f; i++)
for (int j = y; j < y + k && f; j++)
if (w[i][j] != cmp)
{
f = false;
int t = k / 3;
for (int a = x, b = 0; b < 3; a += t, b++)
for (int c = y, d = 0; d < 3; c += t, d++)
dfs(a, c, t);
}
if(f) d[cmp + 1]++;
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
scanf("%d", &w[i][j]);
dfs(0, 0, n);
for (int i : d) cout << i << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment