Language: C++

#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

const int N = 105;

int h, w, a;
char m[N][N];
bool dis[N][N][15][15][4];

typedef tuple<int,int,int,int,int,int> T;
int dy[4] = {0,1,0,-1};
int dx[4] = {1,0,-1,0};

int bfs(int h, int w, T p, T g){
	priority_queue<T, vector<T>, greater<T>> que;
	if(get<0>(p) + 1 > h or m[get<0>(p) + 1][get<1>(p)] == '#') return INF;

	dis[get<0>(p) + 1][get<0>(p)][a][a][1] = 1;
	que.push(T(0, get<0>(p) + 1, get<1>(p), a, a, 1));

	while(not que.empty()){
		int c, y, x, p, q, d;
		tie(c,y,x,p,q,d) = que.top(); que.pop();
		dis[y][x][p][q][d] = 1;
		if(y == get<0>(g) and x == get<1>(g)) break;
		rep(i,4){
			if((d + 2) % 4 == i) continue;

			int ny = y + dy[i];
			int nx = x + dx[i];
			int np = p, nq = q;
			int nc = c;
			
			if(d == 0 || d == 2){
				if((d + 1) % 4 == i){
					np = p - 1;
					nc++;
				}else if((d - 1 + 4) % 4 == i){
					nq = q - 1;
					nc++;
				}
			}else{
				if((d + 1) % 4 == i){
					nq = q - 1;
					nc++;
				}else if((d - 1 + 4) % 4 == i){
					np = p - 1;
					nc++;
				}
			}
			if(np < 0 || nq < 0) continue;

			if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			//cout << ny << ' ' << nx << ' ' << np << ' ' << nq << endl;
				//cout << next.x << ' ' << next.y << ' ' << next.p << ' ' << next.q << ' ' << next.d << endl;
			if(not dis[ny][nx][np][nq][i] && m[ny][nx] != '#' &&
					not (m[y][x] == 'S' && d != i) &&
					not (m[ny][nx] == 'S' && i == 3)){
				//cout << next.x << ' ' << next.y << ' ' << next.p << ' ' << next.q << ' ' << next.d << endl;
				que.emplace(nc,ny,nx,np,nq,i);
			}
		}
	}

	int ans = INF;
	rep(i,a + 1){
		rep(j,a + 1){
			rep(k,4){
				if(dis[get<0>(g)][get<1>(g)][i][j][k] == false) continue;
				ans = min(ans, a - i + a - j);
			}
		}
	}

	return ans;
}


int main(){
	cin >> h >> w >> a;

	T s, g;
	rep(i,h) rep(j,w){
		cin >> m[i][j];
		if(m[i][j] == 'S') s = T{i,j,0,0,0};
		if(m[i][j] == 'G') g = T{i,j,0,0,0};
	}

	int ans = bfs(h, w, s, g);
	cout << (ans == INF ? -1 : ans) << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:90:51: error: no matching function for call to 'std::tuple<int, int, int, int, int, int>::tuple(<brace-enclosed initializer list>)'
   90 |                 if(m[i][j] == 'S') s = T{i,j,0,0,0};
      |                                                   ^
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/tuple:1646:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_Args2 ...>&&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int, int, int}]'
 1646 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1646:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:1634:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_Args2 ...>&&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int, int, int}]'
 1634 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1634:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:1623:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<_Valid>::__is_explicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_Args2 ...>&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int, int, int}]'
 1623 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1623:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:1611:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<_Valid>::__is_implicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_Args2 ...>&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int, int, int}]'
 1611 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1611:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:1603:9: note: candidate: 'template<class _Alloc> std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, std::tuple< <template-parameter-1-1> >&&) [with _Elements = {int, int, int, int, int, int}]'
 1603 |         tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:1603:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:1598:9: note: candidate: 'template<class _Alloc> std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple< <template-parameter-1-1> >&) [with _Elements = {int, int, int, int, int, int}]'
 1598 |         tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:1598:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:1591:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, _UElements&& ...) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int, int, int}]'
 1591 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1591:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/tuple:1588:55: error: no type named 'type' in 'struct std::enable_if<false, bool>'
 1588 |                _ExplicitCtor<_Valid, _UElements...> = false>
      |                                                       ^~~~~
/usr/include/c++/14/tuple:1581:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, _UElements&& ...) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int, int, int}]'
 1581 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1581:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/tuple:1579:55: error: no type named 'type' in 'struct std::enable_if<false, bool>'
 1579 |                _ImplicitCtor<_Valid, _UElements...> = true>
      |                                                       ^~~~
/usr/include/c++/14/tuple:1573:9: note: candidate: 'template<class _Alloc, bool _NotEmpty, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<_Valid>::__is_explicitly_constructible<const int&, const int&, const int&, const int&, const int&, const int&>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const _Elements& ...) [with bool _NotEmpty = _Alloc; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<const _Elements& ...>(), bool>::type <anonymous> = _NotEmpty; _Elements = {int, int, int, int, int, int}]'
 1573 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1573:9: note:   candidate expects 8 arguments, 5 provided
/usr/include/c++/14/tuple:1565:9: note: candidate: 'template<class _Alloc, bool _NotEmpty, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<_Valid>::__is_implicitly_constructible<const int&, const int&, const int&, const int&, const int&, const int&>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const _Elements& ...) [with bool _NotEmpty = _Alloc; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<const _Elements& ...>(), bool>::type <anonymous> = _NotEmpty; _Elements = {int, int, int, int, int, int}]'
 1565 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1565:9: note:   candidate expects 8 arguments, 5 provided
/usr/include/c++/14/tuple:1559:9: note: candidate: 'template<class _Alloc, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<((bool)std::is_object<_Tp>::value)>::__is_explicitly_default_constructible(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&) [with typename std::enable_if<_TCC<((bool)std::is_object<_Alloc>::value)>::__is_explicitly_default_constructible(), bool>::type <anonymous> = _Alloc; _Elements = {int, int, int, int, int, int}]'
 1559 |         tuple(allocator_arg_t __tag, const _Alloc& __a)
      |         ^~~~~
/usr/include/c++/14/tuple:1559:9: note:   candidate expects 2 arguments, 5 provided
/usr/include/c++/14/tuple:1552:9: note: candidate: 'template<class _Alloc, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<((bool)std::is_object<_Tp>::value)>::__is_implicitly_default_constructible(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&) [with typename std::enable_if<_TCC<((bool)std::is_object<_Alloc>::value)>::__is_implicitly_default_constructible(), bool>::type <anonymous> = _Alloc; _Elements = {int, int, int, int, int, int}]'
 1552 |         tuple(allocator_arg_t __tag, const _Alloc& __a)
      |         ^~~~~
/usr/include/c++/14/tuple:1552:9: note:   candidate expects 2 arguments, 5 provided
/usr/include/c++/14/tuple:1542:9: note: candidate: 'template<class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int, int, int>::_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> > constexpr std::tuple< <template-parameter-1-1> >::tuple(std::tuple<_Args1 ...>&&) [with _UElements = {_UElements ...}; bool _Valid = _Valid; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> = <anonymous>; _Elements = {int, int, int, int, int, int}]'
 1542 |         tuple(tuple<_UElements...>&& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:1542:9: note:   candidate expects 1 a