Language: C++

#include<iostream>
#include<queue>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
vector<vector<__int8>>S;
bool dp[13][160];
vector<tuple<vector<vector<short>>, int, vector<tuple<short, short, short>>>>Vec;
vector<vector<short>> solve(vector<vector<short>>p, int x, int y, int r) {
	if (r == 1) { p[x][y]--; p[x + 1][y]--; p[x - 1][y]--; p[x][y - 1]--; p[x][y + 1]--; }
	if (r == 2) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; }
	if (r == 3) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; p[x + 2][y]--; p[x][y + 2]--; p[x - 2][y]--; p[x][y - 2]--; }
	return p;
}
bool hantei(vector<vector<short>>p) {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (p[i][j] < 0)return false;
		}
	}
	bool OKs[10][10]; for (int i = 0; i < 100; i++)OKs[i / 10][i % 10] = false;
	for (int i = 1; i < 9; i++) {
		for (int j = 1; j < 9; j++) {
			if (p[i][j] == 0)continue;
			if (p[i - 1][j] >= 1 && p[i + 1][j] >= 1 && p[i][j - 1] >= 1 && p[i][j + 1] >= 1) {
				OKs[i][j] = true; OKs[i - 1][j] = true; OKs[i][j - 1] = true; OKs[i][j + 1] = true; OKs[i + 1][j] = true;
			}
			bool OK4 = true;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)if (p[i + k][j + l] == 0)OK4 = false;
			if (OK4 == false)continue;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)OKs[i + k][j + l] = true;
		}
	}
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			if (OKs[i][j] == false && p[i][j] >= 1)return false;
		}
	}
	return true;
}
void zen_shori() {
	vector<vector<short>>ZERO; queue<tuple<vector<vector<short>>, int, vector<tuple<short, short, short>>>>Q2;
	vector<tuple<short, short, short>>ZERO3;
	for (int i = 0; i < 10; i++) { vector<short>ZERO5(10, 0); ZERO.push_back(ZERO5); }
	Q2.push(make_tuple(ZERO, 0, ZERO3));
	while (!Q2.empty()) {
		vector<vector<short>>a1 = get<0>(Q2.front()); int a2 = get<1>(Q2.front());
		vector<tuple<short, short, short>>a3 = get<2>(Q2.front());
		Vec.push_back(make_tuple(a1, a2, a3)); Q2.pop(); if (a2 == 2)continue;
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					vector<vector<short>>a4 = solve(a1, j, k, i);
					vector<tuple<short, short, short>>a5 = a3; a5.push_back(make_tuple(j, k, i));
					Q2.push(make_tuple(a4, a2 + 1, a5));
				}
			}
		}
	}
	for (int i = 0; i < Vec.size(); i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				get<0>(Vec[i])[j][k] *= -1;
			}
		}
	}
	sort(Vec.begin(), Vec.end());
}
int main() {
	int n; cin >> n; dp[0][0] = true;
	for (int i = 0; i < 12; i++) {
		for (int j = 0; j < 160; j++) {
			if (dp[i][j] == false)continue;
			dp[i + 1][j + 5] = true; dp[i + 1][j + 9] = true; dp[i + 1][j + 13] = true;
		}
	}
	for (int i = 0; i < 10; i++) { vector<short>V(10, 0); S.push_back(V); }
	vector<vector<short>>START = S; int SUM = 0;
	for (int i = 0; i < 10; i++)for (int j = 0; j < 10; j++) { cin >> S[i][j]; SUM += S[i][j]; }
	queue<tuple<vector<vector<short>>, int, vector<tuple<short, short, short>>, int>> Q;
	vector<tuple<short, short, short>>ZERO;
	Q.push(make_tuple(S, 0, ZERO, SUM));
	zen_shori();

	while (!Q.empty()) {
		vector<vector<short>>a1 = get<0>(Q.front()); int a2 = get<1>(Q.front());
		vector<tuple<short, short, short>>a3 = get<2>(Q.front()); int a4 = get<3>(Q.front()); Q.pop();
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };

		for (int i = 1; i <= 3; i++) {
			int rem1 = a4 - P[i], rem2 = n - (a2 + 1); bool OK = true;
			if (dp[rem2][rem1] == false)OK = false;
			if (OK == false)continue;
			int LIM = 0; if (a3.size() >= 1) LIM = get<0>(a3[a3.size() - 1]) * 10 + get<1>(a3[a3.size() - 1]);
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					int DD = j * 10 + k;
					if (DD < LIM) continue;
					vector<vector<short>>G = solve(a1, j, k, i);
					vector<tuple<short,short,short>>H = a3;
					if (hantei(G) == false)goto F;
					H.push_back(make_tuple(j, k, i));
					if (G == START && a2 + 1 == n) {
						for (int j = 0; j < H.size(); j++) {
							cout << get<1>(H[j]) << ' ' << get<0>(H[j]) << ' ' << get<2>(H[j]) << endl;
						}
						goto E;
					}
					if (a2 + 1 >= 10) {
						int P = lower_bound(Vec.begin(), Vec.end(), make_tuple(G, 0, ZERO)) - Vec.begin();
						if (P < Vec.size() && get<0>(Vec[P]) == G) {
							for (int j = 0; j < H.size(); j++) {
								cout << get<1>(H[j]) << ' ' << get<0>(H[j]) << ' ' << get<2>(H[j]) << endl;
							}
							vector<tuple<short, short, short>>J = get<2>(Vec[P]);
							for (int j = 0; j < J.size(); j++) {
								cout << get<1>(J[j]) << ' ' << get<0>(J[j]) << ' ' << get<2>(J[j]) << endl;
							}
							goto E;
						}
					}
					Q.push(make_tuple(G, a2 + 1, H, a4 - P[i]));
				F:;
				}
			}
		}
	}
E:;
	return 0;
}

Compiler output:
a.cc:7:15: error: '__int8' was not declared in this scope; did you mean 'u_int'?
    7 | vector<vector<__int8>>S;
      |               ^~~~~~
      |               u_int
a.cc:7:15: error: template argument 1 is invalid
a.cc:7:15: error: template argument 2 is invalid
a.cc:7:21: error: template argument 1 is invalid
    7 | vector<vector<__int8>>S;
      |                     ^~
a.cc:7:21: error: template argument 2 is invalid
a.cc: In function 'int main()':
a.cc:79:65: error: request for member 'push_back' in 'S', which is of non-class type 'int'
   79 |         for (int i = 0; i < 10; i++) { vector<short>V(10, 0); S.push_back(V); }
      |                                                                 ^~~~~~~~~
a.cc:80:38: error: conversion from 'int' to non-scalar type 'std::vector<std::vector<short int> >' requested
   80 |         vector<vector<short>>START = S; int SUM = 0;
      |                                      ^
a.cc:81:76: error: invalid types 'int[int]' for array subscript
   81 |         for (int i = 0; i < 10; i++)for (int j = 0; j < 10; j++) { cin >> S[i][j]; SUM += S[i][j]; }
      |                                                                            ^
a.cc:81:92: error: invalid types 'int[int]' for array subscript
   81 |         for (int i = 0; i < 10; i++)for (int j = 0; j < 10; j++) { cin >> S[i][j]; SUM += S[i][j]; }
      |                                                                                            ^
a.cc:84:15: error: no matching function for call to 'std::queue<std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int> >::push(std::tuple<int, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>)'
   84 |         Q.push(make_tuple(S, 0, ZERO, SUM));
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_queue.h:283:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>; _Sequence = std::deque<std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>, std::allocator<std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int> > >; value_type = std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>]'
  283 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:283:30: note:   no known conversion for argument 1 from 'std::tuple<int, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>' to 'const std::queue<std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int> >::value_type&' {aka 'const std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>&'}
  283 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:288:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(value_type&&) [with _Tp = std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>; _Sequence = std::deque<std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>, std::allocator<std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int> > >; value_type = std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>]'
  288 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:288:25: note:   no known conversion for argument 1 from 'std::tuple<int, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>' to 'std::queue<std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int> >::value_type&&' {aka 'std::tuple<std::vector<std::vector<short int, std::allocator<short int> >, std::allocator<std::vector<short int, std::allocator<short int> > > >, int, std::vector<std::tuple<short int, short int, short int>, std::allocator<std::tuple<short int, short int, short int> > >, int>&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~