Language: C++

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<VI> VVI;
template<class T> T gcd( T a, T b ) {
	return !b ? a : gcd( b, a % b );
}
template<class T> T lcm( T a, T b ) {
	return a / gcd( a, b ) * b;
}
template<class T> string print_v( vector<T> v ) {
	OSS oss;
	for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end();
          ++it_i ) {
		oss << *it_i << ", ";
	}
	return oss.str();
}

const int ks = 1;
const int kr[ks] = { -1, -1, 1, -1 };
const int kc[ks] = { -1, -1, -1, -1 };
int w, h;

void print( VVI T ) {
    for ( int i = 0; i < h; ++ i ) {
        for ( int j = 0; j < w; ++ j ) {
            cout << T[i][j] << ",";
        }
        cout << endl;
    }
    cout << endl;
}

VVI flip( VVI T, int r, int c ) {
    VVI NT = T;
    int cand = 0;
    int cl = 0;
    int ck;
    for ( int L = min( w, h ); L > 0; -- L ) {
        for ( int k = 0; k < ks; ++ k ) {
            int cnt = 0;
            for ( int i = 0; i < L; ++ i ) {
                for ( int j = 0; j < L; ++ j ) {
                    int nr = r + i * kr[k];
                    int nc = c + j * kc[k];
                    if ( nr < 0 || nr >= h ) goto IGNORE;
                    if ( nc < 0 || nc >= w ) goto IGNORE;
                    if ( T[nr][nc] == 0 ) goto IGNORE;
                    if ( T[nr][nc] == 1 ) cnt ++;
                }
            }
            if ( cnt > cand ) {
                cand = cnt;
                ck = k;
                cl = L;
            }
        IGNORE:;
        }
    }
    for ( int i = 0; i < cl; ++ i ) {
        for ( int j = 0; j < cl; ++ j ) {
            int nr = r + i * kr[ck];
            int nc = c + j * kc[ck];
            NT[nr][nc] = 2;
        }
    }
    return NT;
}

int main() {
    while ( cin >> w >> h && w ) {
        VVI T( h, VI( w ) );
        for ( int i = 0; i < h; ++ i ) {
            for ( int j = 0; j < w; ++ j ) {
                cin >> T[i][j];
            }
        }
        int res = 0;
        for ( int i = h - 1; i >= 0; -- i ) {
            for ( int j = w - 1; j >= 0; -- j ) {
                if ( T[i][j] != 1 ) continue;
                T = flip( T, i, j );
                // cout << i << ", " << j << ": " << ret.first << endl;
                res ++;
                // cout << "before: " << endl;
                // print( T );
                // cout << "after: " << endl;
                // print( ret.second );
                // cout << endl;
            }
        }
        cout << res << endl;
    }
	return 0;
}

Compiler output:
a.cc:39:36: error: too many initializers for 'const int [1]'
   39 | const int kr[ks] = { -1, -1, 1, -1 };
      |                                    ^
a.cc:40:37: error: too many initializers for 'const int [1]'
   40 | const int kc[ks] = { -1, -1, -1, -1 };
      |                                     ^