#include <bits/stdc++.h>
using namespace std;

int n;
int res[4];
int board[2200][2200];
bool check(int x,int y,int n) {
    for(int i=x; i<x+n; i++) {
        for(int j=y; j<y+n; j++) {
            if(board[x][y]!=board[i][j]) return false;
        }
    }
    return true;
}
void paper(int x,int y,int n) {
    if(check(x,y,n)) {
        res[board[x][y]+1]++;
        return;
    }
    
    n/=3;
    /*for(int i=x;i<x+3*n ;i+=n){
        for(int j=y; j<y+3*n; j+=n) {
            paper(i,j,n);
        }
      } */
    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            paper(x+i*n,y+j*n,n);
        }
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++){
            cin >> board[i][j];
        }
    }
    paper(0,0,n);
    for(int i=0; i<3; i++) cout << res[i] << '\n';
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: