1780번: 종이의 개수
#include<cstdio>
int paper[2187][2187], count[3];
void countPaper(int n, int x, int y);
int main()
{
int n;
scanf("%d", &n);
for(int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
scanf("%d", &paper[i][j]);
countPaper(n, 0, 0);
printf("%d\n%d\n%d", count[0], count[1], count[2]);
}
void countPaper(int n, int x, int y)
{
bool same = 1;
for (int i = y; i < y + n && same == 1; ++i)
for (int j = x; j < x + n && same == 1; ++j)
if (paper[y][x] != paper[i][j])
same = 0;
if (same == 1)
++count[paper[y][x] + 1];
else
{
n /= 3;
countPaper(n, x, y);
countPaper(n, x + n, y);
countPaper(n, x + (2 * n), y);
countPaper(n, x, y + n);
countPaper(n, x + n, y + n);
countPaper(n, x + (2 * n), y + n);
countPaper(n, x, y + (2 * n));
countPaper(n, x + n, y + (2 * n));
countPaper(n, x + (2 * n), y + (2 * n));
}
}