Language: C++

#include <iostream>
#include <vector>
using namespace std;
#define loop(x, n) for(int x = 0; x < n; ++ x)

int h, w, n;

void fall(int xs, int ys, vector<vector<char> > & field) {
	if (ys + 1 < h && field[ys][xs] != '.' && field[ys + 1][xs] == '.') {
		field[ys + 1][xs] = field[ys][xs];
		field[ys][xs] = '.';
		fall(xs, ys + 1, field);
	}
}

void remakeField(vector<vector<char> > & field) {
	for (int i = h - 1; i >= 0; i--) {
		loop(j,w)
		{
			fall(j, i, field);
		}
	}
}
void findSame(int di, int xs, int ys, int nx, int ny,
		vector<vector<char> > & field, char begin, int result[w * h][4]) {
	//left
	if (di == 0) {
		if (nx - 1 >= 0 && field[ny][nx - 1] == begin) {
			result[ys * w + xs][0] = result[ys * w + xs][0] + 1;
			findSame(di, xs, ys, nx - 1, ny, field, begin, result);
		}
	}
	//up
	if (di == 1) {
		if (ny - 1 >= 0 && field[ny - 1][nx] == begin) {
			result[ys * w + xs][1] = result[ys * w + xs][1] + 1;

			if (begin == 'Y') {
				cout << ys << " !! " << xs << " !! " << result[ys * w + xs][1]
						<< endl;
			}
			findSame(di, xs, ys, nx, ny - 1, field, begin, result);
		}
	}
	//right
	if (di == 2) {
		if (nx + 1 < w && field[ny][nx + 1] == begin) {
			result[ys * w + xs][2] = result[ys * w + xs][2] + 1;
			findSame(di, xs, ys, nx + 1, ny, field, begin, result);
		}
	}
	//down
	if (di == 3) {
		if (ny + 1 < h && field[ny + 1][nx] == begin) {
			result[ys * w + xs][3] = result[ys * w + xs][3] + 1;
			findSame(di, xs, ys, nx, ny + 1, field, begin, result);
		}
	}
}


int newCheck(int result[w * h][4], vector<vector<char> > & field) {
	loop(i,h)
	{
		loop(j,w)
		{
			char begin = field[i][j];
			if (begin != '.') {
				loop(z,4)
				{
					result[i * w + j][z] = 1;
					findSame(z, j, i, j, i, field, begin, result);
				}
			}
		}
	}
	int ifReamke = 0;
	loop(i,h)
	{
		loop(j,w)
		{
			loop(z,4)
			{
				int temp = result[i * w + j][z];
				if (temp >= n) {
					ifReamke++;
					if (z == 0) {
						loop(q,temp)
						{
							field[i][j - q] = '.';
						}
					}
					if (z == 1) {
						loop(q,temp)
						{
							field[i - q][j] = '.';
						}
					}
					if (z == 2) {
						loop(q,temp)
						{
							field[i][j + q] = '.';
						}
					}
					if (z == 3) {
						loop(q,temp)
						{
							field[i + q][j] = '.';
						}
					}
				}
			}
		}
	}
	return ifReamke;
}

bool isAC(vector<vector<char> > & field) {
	int count = 0;
	loop(i,h)
	{
		loop(j,w)
		{
			if (field[i][j] == '.') {
				count++;
			}
		}
	}
	if (count == w * h) {
		return true;
	} else {
		return false;
	}
}

bool checkAll(vector<vector<char> > & field) {

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w - 1; j++) {
			if (field[i][j] != '.' && field[i][j + 1] != '.') {
				vector<vector<char> > temp(field);

				char tChar = temp[i][j];
				temp[i][j] = temp[i][j + 1];
				temp[i][j + 1] = tChar;

				while (true) {
					int result[w * h][4];
					loop(xx,w*h)
					{
						loop(xxx,4)
						{
							result[xx][xxx] = 0;
						}
					}
					int ifRemake = newCheck(result, temp);
					if (ifRemake > 0) {
						remakeField(temp);
					}else{
						break;
					}
				}

				if(isAC(temp)){
					return true;
				}

			}
		}
	}
	return false;
}

int main() {
	cin >> h >> w >> n;
	vector<vector<char> > field;
	for (int i = 0; i < h; i++) {
		vector<char> temp;
		for (int j = 0; j < w; j++) {
			char input;
			cin >> input;
			temp.push_back(input);
		}
		field.push_back(temp);
	}

	if (checkAll(field)) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;

	}


}



Compiler output:
a.cc:25:73: error: size of array 'result' is not an integral constant-expression
   25 |                 vector<vector<char> > & field, char begin, int result[w * h][4]) {
      |                                                                       ~~^~~
a.cc:62:27: error: size of array 'result' is not an integral constant-expression
   62 | int newCheck(int result[w * h][4], vector<vector<char> > & field) {
      |                         ~~^~~