Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,k,n) for(int i=k;i<(int)(n);i++)

#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second

typedef long long ll;
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};

int main(){
//    ifstream in("cin.txt");
//    cin.rdbuf(in.rdbuf());
    int h,w,c;
    while(cin >> h >> w >> c,h){
        int ma = 0;
        int p[10][10] = {};
        rep(y,h)rep(x,w) cin >> p[y][x];
        int a[6] = {};
        rep(bit,pow(6,4)){
            int tmp_bit = bit;
            rep(i,4){
                a[i] = tmp_bit%6;
                tmp_bit/=6;
                a[i]+=1;
                if(a>0 && a[i-1] == a[i]) a[0] = -1;
//                cout << a[i] << " ";
            }
            if(a[0] == -1 || a[3] == c) continue;
//            cout << endl;
            a[4] = c;
//            rep(i,c) cout << a[i] << " ";
//            cout << endl;
            int t[10][10];
            rep(y,h)rep(x,w) t[y][x] = p[y][x];

            rep(i,5){

                queue<pii> que;
                que.push(pii(0,0));1
                int now_color = t[0][0];
                bool u[10][10] = {};
                while(!que.empty()){
                    int x,y;
                    tie(x,y) = que.front();
                    que.pop();
                    if(u[y][x]) continue;
                    u[y][x] = true;
                    t[y][x] = a[i];
                    rep(d,4){
                        int nx = x + dx[d];
                        int ny = y + dy[d];
                        if(nx < 0 || w <= nx ||
                                ny < 0 || h <= ny) continue;
                        if(u[ny][nx] || t[ny][nx] != now_color) continue;
                        que.push(pii(nx,ny));
                    }
                }
            }
            int cnt = 0;
            queue<pii> qe;
            qe.push(pii(0,0));
            bool uu[10][10] = {};

            while(!qe.empty()) {
                int xp, yp;

                tie(xp, yp) = qe.front();
                qe.pop();
                if(uu[yp][xp]) continue;
                cnt += 1;
                uu[yp][xp] = true;
                rep(d, 4) {
                    int nx = xp + dx[d];
                    int ny = yp + dy[d];
                    if (nx < 0 || w <= nx ||
                        ny < 0 || h <= ny)
                        continue;
                    if(uu[ny][nx]) continue;
                    if(t[ny][nx] != c) continue;
                    qe.push(pii(nx, ny));
                }
            }
            ma = max(ma,cnt);
        };
        cout << ma << endl;

    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:31:21: error: ordered comparison of pointer with integer zero ('int*' and 'int')
   31 |                 if(a>0 && a[i-1] == a[i]) a[0] = -1;
      |                    ~^~
a.cc:45:37: error: expected ';' before 'int'
   45 |                 que.push(pii(0,0));1
      |                                     ^
      |                                     ;
   46 |                 int now_color = t[0][0];
      |                 ~~~                  
a.cc:60:54: error: 'now_color' was not declared in this scope
   60 |                         if(u[ny][nx] || t[ny][nx] != now_color) continue;
      |                                                      ^~~~~~~~~