Language: C++

#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


class Dice{
public:


	void roll(char dst){
		for(int i = 0; i < 6; i++) work[i] = color[i];
		switch(dst){
		case 'E':
			setColor(work[3],work[1],work[0],work[5],work[4],work[2]);
			break;
		case 'S':
			setColor(work[1],work[5],work[2],work[3],work[0],work[4]);
			break;
		case 'N':
			setColor(work[4],work[0],work[2],work[3],work[5],work[1]);
			break;
		case 'W':
			setColor(work[2],work[1],work[5],work[0],work[4],work[3]);
			break;
		}
	};

	char getTop(){
		return color[0];
	}

	void setColor(char n0,char n1,char n2,char n3,char n4,char n5){
		color[0] = n0;
		color[1] = n1;
		color[2] = n2;
		color[3] = n3;
		color[4] = n4;
		color[5] = n5;
	}

	void init(){
		setColor('W','R','B','B','R','W');
	}

	void to_empty(){
		setColor('E','E','E','E','E','E');
	}

	char color[6],work[6];
};

struct Info{
	Dice board[3][3];
	int empty_row,empty_col,num_step;
};

int POW[10];
int first_row,first_col;
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
Info goal;

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= 2 && col >= 0 && col <= 2)return true;
	else{
		return false;
	}
}

int calcDiff(Info info){

	int ret = 0;

	for(int row = 0; row < 3; row++){
		for(int col = 0; col < 3; col++){
			if(info.board[row][col] != goal.board[row][col]){
				ret++;
			}
		}
	}

	return ret;
}

void copyInfo(Info& to,Info from){

	for(int row = 0; row < 3; row++){
		for(int col = 0; col < 3; col++){
			to.board[row][col] = from.board[row][col];
		}
	}

	to.num_step = from.num_step+1;
}

bool FLG;

void recursive(Info info,int max_depth){

	if(FLG)return;

	int tmp_diff = calcDiff(info);

	if(tmp_diff == 0){
		FLG = true;
		return;
	}

	if(info.num_step+tmp_diff > max_depth || info.num_step == max_depth)return;

	int adj_row,adj_col;

	for(int i = 0; i < 4; i++){
		adj_row = info.empty_row+diff_row[i];
		adj_col = info.empty_col+diff_col[i];

		if(!rangeCheck(adj_row,adj_col))continue;

		Info next_info;
		copyInfo(next_info,info);

		switch(i){
		case 0:
			next_info.board[adj_row][adj_col].roll('S');
			break;
		case 1:
			next_info.board[adj_row][adj_col].roll('E');
			break;
		case 2:
			next_info.board[adj_row][adj_col].roll('W');
			break;
		case 3:
			next_info.board[adj_row][adj_col].roll('N');
			break;
		}

		next_info.board[info.empty_row][info.empty_col] = next_info.board[adj_row][adj_col];
		next_info.board[adj_row][adj_col].to_empty();
		next_info.empty_row = adj_row;
		next_info.empty_col = adj_col;

		recursive(next_info,max_depth);
	}
}


void func(){

	first_row--;
	first_col--;

	char buf[2];

	for(int row = 0; row < 3; row++){
		for(int col = 0; col < 3; col++){
			scanf("%s",buf);
			goal.board[row][col].color[0] = buf[0];
		}
	}

	Info first;
	for(int row = 0; row < 3; row++){
		for(int col = 0; col < 3; col++)first.board[row][col].init();
	}
	first.board[first_row][first_col].to_empty();
	first.empty_row = first_row;
	first.empty_col = first_col;
	first.num_step = 0;

	FLG = false;
	int ans;

	for(int max_depth = 0; max_depth <= 30; max_depth++){
		recursive(first,max_depth);
		if(FLG){
			ans = max_depth;
			break;
		}
	}

	if(FLG){
		printf("%d\n",ans);
	}else{
		printf("-1\n");
	}
}


int main(){

	for(int i = 0; i < 10; i++)POW[i] = pow(4,i);

	while(true){
		scanf("%d %d",&first_col,&first_row);
		if(first_col == 0 && first_row == 0)break;

		func();
	}

	return 0;
}



Compiler output:
a.cc: In function 'int calcDiff(Info)':
a.cc:90:49: error: no match for 'operator!=' (operand types are 'Dice' and 'Dice')
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                            ~~~~~~~~~~~~~~~~~~~~ ^~ ~~~~~~~~~~~~~~~~~~~~
      |                                               |                       |
      |                                               Dice                    Dice
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_pair.h:1052:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1052 |     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1052:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::pair<_T1, _T2>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:455:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  455 |     operator!=(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:455:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::reverse_iterator<_Iterator>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
/usr/include/c++/14/bits/stl_iterator.h:500:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  500 |     operator!=(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:500:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::reverse_iterator<_Iterator>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
/usr/include/c++/14/bits/stl_iterator.h:1686:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1686 |     operator!=(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1686:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::move_iterator<_IteratorL>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
/usr/include/c++/14/bits/stl_iterator.h:1753:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1753 |     operator!=(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1753:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::move_iterator<_IteratorL>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
In file included from /usr/include/c++/14/deque:63,
                 from /usr/include/c++/14/stack:62,
                 from a.cc:5:
/usr/include/c++/14/bits/allocator.h:243:5: note: candidate: 'template<class _T1, class _T2> bool std::operator!=(const allocator<_Tp1>&, const allocator<_T2>&)'
  243 |     operator!=(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/include/c++/14/bits/allocator.h:243:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::allocator<_Tp1>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
In file included from /usr/include/c++/14/deque:66:
/usr/include/c++/14/bits/stl_deque.h:2342:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator!=(const deque<_Tp, _Alloc>&, const deque<_Tp, _Alloc>&)'
 2342 |     operator!=(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:2342:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::deque<_Tp, _Alloc>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/deque:81:
/usr/include/c++/14/tuple:2613:5: note: candidate: 'template<class ... _TElements, class ... _UElements> constexpr bool std::operator!=(const tuple<_UTypes ...>&, const tuple<_Elements ...>&)'
 2613 |     operator!=(const tuple<_TElements...>& __t,
      |     ^~~~~~~~
/usr/include/c++/14/tuple:2613:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::tuple<_UTypes ...>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
In file included from /usr/include/c++/14/stack:63:
/usr/include/c++/14/bits/stl_stack.h:380:5: note: candidate: 'template<class _Tp, class _Seq> bool std::operator!=(const stack<_Tp, _Seq>&, const stack<_Tp, _Seq>&)'
  380 |     operator!=(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_stack.h:380:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::stack<_Tp, _Seq>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/queue:63,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_vector.h:2096:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator!=(const vector<_Tp, _Alloc>&, const vector<_Tp, _Alloc>&)'
 2096 |     operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:2096:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::vector<_Tp, _Alloc>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
In file included from /usr/include/c++/14/queue:66:
/usr/include/c++/14/bits/stl_queue.h:404:5: note: candidate: 'template<class _Tp, class _Seq> bool std::operator!=(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&)'
  404 |     operator!=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:404:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::queue<_Tp, _Seq>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
In file included from /usr/include/c++/14/bits/char_traits.h:42,
                 from /usr/include/c++/14/string:42,
                 from a.cc:8:
/usr/include/c++/14/bits/postypes.h:197:5: note: candidate: 'template<class _StateT> bool std::operator!=(const fpos<_StateT>&, const fpos<_StateT>&)'
  197 |     operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/postypes.h:197:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'const std::fpos<_StateT>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
In file included from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54:
/usr/include/c++/14/string_view:651:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator!=(basic_string_view<_CharT, _Traits>, basic_string_view<_CharT, _Traits>)'
  651 |     operator!=(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:651:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'std::basic_string_view<_CharT, _Traits>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
/usr/include/c++/14/string_view:658:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator!=(basic_string_view<_CharT, _Traits>, __type_identity_t<basic_string_view<_CharT, _Traits> >)'
  658 |     operator!=(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:658:5: note:   template argument deduction/substitution failed:
a.cc:90:71: note:   'Dice' is not derived from 'std::basic_string_view<_CharT, _Traits>'
   90 |                         if(info.board[row][col] != goal.board[row][col]){
      |                                                                       ^
/usr/inclu