Language: C++

#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>
#include <bitset>
using namespace std;

#define fi first
#define se second

typedef pair<int,int> pii;

const int dxy[] = {1, 0, -1, 0, 1};
char maze[15][15];
int ice[15][15];
bit set<3000000> visited[12][12];
vector<int> icesq;

struct data {
	int x, y;
	int t, v;
	data(int x_, int y_, int t_, int v_) {
		x = x_;
		y = y_;
		t = t_;
		v = v_;
	}
};

int maketag(int i, int j, int n) {
	if(maze[i][j] != 'X' || ice[i][j] != -1)
		return 0;
	ice[i][j] = n;
	int res = 1;
	for(int k = 0; k < 4; k++)
		res += maketag(i+dxy[k], j+dxy[k+1], n);
	return res;
}

int main() {
	int x, y;
	while(cin >> x >> y, x || y) {
		for(int i = 0; i < 15; i++) {
			for(int j = 0; j < 15; j++) {
				maze[i][j] = '#';
				ice[i][j] = -1;
			}
		}
		for(int i = 0; i < y; i++) {
			scanf("%s", maze[i+1]+1);
			maze[i+1][1+x] = '#';
		}
		icesq.clear();
		int tg = 0;
		pii S, G;
		for(int i = 0; i < y; i++) {
			for(int j = 0; j < x; j++) {
				int res;
				if(maze[i+1][j+1] == 'S') {
					maze[i+1][j+1] = '.';
					S.fi = i+1; S.se = j+1;
				}
				else if(maze[i+1][j+1] == 'G') {
					maze[i+1][j+1] = '.';
					G.fi = i+1; G.se = j+1;
				}

				res = maketag(i+1,j+1,tg);
				if(res != 0) {
					icesq.push_back(res / 2);
					tg++;
				}
			}
		}
/*
		for(int i = 0; i < 14; i++) {
			for(int j = 0; j < 14; j++) {
				cout << maze[i][j];
			} cout << endl;
		}
// */
/*
		for(int i = 0; i < icesq.size(); i++) {
			cout << icesq[i] << " ";
		} cout << endl;
// */
		queue<data> q;
		q.push(data(S.se, S.fi, 0, 0));
		vector<int> radix;
		radix.resize(icesq.size() + 1);
		radix[0] = 1;
		for(int i = 1; i < radix.size(); i++) {
			radix[i] = radix[i-1] * (icesq[i-1] + 1);
		}
		for(int i = 0; i < 12; i++) {
			for(int j = 0; j < 12; j++) {
				visited[i][j].reset();
			}
		}
		while(!q.empty()) {
			data cur = q.front();
			q.pop();
//			cout << cur.y << " " << cur.x << " " << cur.t << ":";
			if(cur.y == G.fi && cur.x == G.se) {
				cout << cur.t << endl;
				break;
			}
			for(int i = 0; i < 4; i++) {
				int nx, ny;
				ny = cur.y + dxy[i];
				nx = cur.x + dxy[i+1];

				if(!(0 < nx && nx <= x && 0 < ny && ny <= y)) {
					continue;
				}

				if(maze[ny][nx] == '.') {
					if(!visited[ny-1][nx-1][cur.v]) {
						visited[ny-1][nx-1][cur.v] = true;
						q.push(data(nx, ny, cur.t + 1, cur.v));
					}
				}
				else if(maze[ny][nx] == 'X') {
					int flgcnts;
					flgcnts = (cur.v % radix[ice[ny][nx]+1]) / radix[ice[ny][nx]];
					if(flgcnts < icesq[ice[ny][nx]]) {
						int tmp = cur.v + radix[ice[ny][nx]];
						if(!visited[ny-1][nx-1][tmp]) {
							visited[ny-1][nx-1][tmp] = true;
							q.push(data(nx, ny, cur.t + 1, tmp));
						}
					}
				}
			}
		}
//		cout << "----------" << endl;
	}
}

Compiler output:
a.cc:19:1: error: 'bit' does not name a type
   19 | bit set<3000000> visited[12][12];
      | ^~~
a.cc: In function 'int main()':
a.cc:90:27: error: template argument 1 is invalid
   90 |                 queue<data> q;
      |                           ^
a.cc:90:27: error: template argument 2 is invalid
a.cc:91:19: error: request for member 'push' in 'q', which is of non-class type 'int'
   91 |                 q.push(data(S.se, S.fi, 0, 0));
      |                   ^~~~
a.cc:91:24: error: reference to 'data' is ambiguous
   91 |                 q.push(data(S.se, S.fi, 0, 0));
      |                        ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data {
      |        ^~~~
a.cc:100:33: error: 'visited' was not declared in this scope
  100 |                                 visited[i][j].reset();
      |                                 ^~~~~~~
a.cc:103:26: error: request for member 'empty' in 'q', which is of non-class type 'int'
  103 |                 while(!q.empty()) {
      |                          ^~~~~
a.cc:104:25: error: reference to 'data' is ambiguous
  104 |                         data cur = q.front();
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data {
      |        ^~~~
a.cc:105:27: error: request for member 'pop' in 'q', which is of non-class type 'int'
  105 |                         q.pop();
      |                           ^~~
a.cc:107:28: error: 'cur' was not declared in this scope
  107 |                         if(cur.y == G.fi && cur.x == G.se) {
      |                            ^~~
a.cc:113:38: error: 'cur' was not declared in this scope
  113 |                                 ny = cur.y + dxy[i];
      |                                      ^~~
a.cc:121:45: error: 'visited' was not declared in this scope
  121 |                                         if(!visited[ny-1][nx-1][cur.v]) {
      |                                             ^~~~~~~
a.cc:123:51: error: request for member 'push' in 'q', which is of non-class type 'int'
  123 |                                                 q.push(data(nx, ny, cur.t + 1, cur.v));
      |                                                   ^~~~
a.cc:123:56: error: reference to 'data' is ambiguous
  123 |                                                 q.push(data(nx, ny, cur.t + 1, cur.v));
      |                                                        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data {
      |        ^~~~
a.cc:131:53: error: 'visited' was not declared in this scope
  131 |                                                 if(!visited[ny-1][nx-1][tmp]) {
      |                                                     ^~~~~~~
a.cc:133:59: error: request for member 'push' in 'q', which is of non-class type 'int'
  133 |                                                         q.push(data(nx, ny, cur.t + 1, tmp));
      |                                                           ^~~~
a.cc:133:64: error: reference to 'data' is ambiguous
  133 |                                                         q.push(data(nx, ny, cur.t + 1, tmp));
      |                                                                ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data {
      |        ^~~~