Language: C++

#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>
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];
bitset<1000000> 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:18:1: error: 'bitset' does not name a type
   18 | bitset<1000000> visited[12][12];
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:89:27: error: template argument 1 is invalid
   89 |                 queue<data> q;
      |                           ^
a.cc:89:27: error: template argument 2 is invalid
a.cc:90:19: error: request for member 'push' in 'q', which is of non-class type 'int'
   90 |                 q.push(data(S.se, S.fi, 0, 0));
      |                   ^~~~
a.cc:90:24: error: reference to 'data' is ambiguous
   90 |                 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:21:8: note:                 'struct data'
   21 | struct data {
      |        ^~~~
a.cc:99:33: error: 'visited' was not declared in this scope
   99 |                                 visited[i][j].reset();
      |                                 ^~~~~~~
a.cc:102:26: error: request for member 'empty' in 'q', which is of non-class type 'int'
  102 |                 while(!q.empty()) {
      |                          ^~~~~
a.cc:103:25: error: reference to 'data' is ambiguous
  103 |                         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:21:8: note:                 'struct data'
   21 | struct data {
      |        ^~~~
a.cc:104:27: error: request for member 'pop' in 'q', which is of non-class type 'int'
  104 |                         q.pop();
      |                           ^~~
a.cc:106:28: error: 'cur' was not declared in this scope
  106 |                         if(cur.y == G.fi && cur.x == G.se) {
      |                            ^~~
a.cc:112:38: error: 'cur' was not declared in this scope
  112 |                                 ny = cur.y + dxy[i];
      |                                      ^~~
a.cc:120:45: error: 'visited' was not declared in this scope
  120 |                                         if(!visited[ny-1][nx-1][cur.v]) {
      |                                             ^~~~~~~
a.cc:122:51: error: request for member 'push' in 'q', which is of non-class type 'int'
  122 |                                                 q.push(data(nx, ny, cur.t + 1, cur.v));
      |                                                   ^~~~
a.cc:122:56: error: reference to 'data' is ambiguous
  122 |                                                 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:21:8: note:                 'struct data'
   21 | struct data {
      |        ^~~~
a.cc:130:53: error: 'visited' was not declared in this scope
  130 |                                                 if(!visited[ny-1][nx-1][tmp]) {
      |                                                     ^~~~~~~
a.cc:132:59: error: request for member 'push' in 'q', which is of non-class type 'int'
  132 |                                                         q.push(data(nx, ny, cur.t + 1, tmp));
      |                                                           ^~~~
a.cc:132:64: error: reference to 'data' is ambiguous
  132 |                                                         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:21:8: note:                 'struct data'
   21 | struct data {
      |        ^~~~