Language: C++

//AOJ 0121

//include
#include<bits/stdc++.h>

//using
using namespace std;


//define static const typedef
#define FOR(i, s, n) for(int (i) = (s); (i) < (n); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SORT(a) sort(ALL(a))
#define RSORT(a) sort(RALL(a))
#define DUMP(x) cerr << #x << " = " << x << "\n";
#define DEBUG(x) cerr << #x << " = " << x << " (L:" << __LINE__ << ") " << __FILE__ << "\n";
#define F first
#define S second

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;

static const int INF = 1 << 25;

//global
static vector<char> clear(8);
static vector<vector<char> > move(8);
static vector<char> now(8); 
static char b;
static queue<pair<pair<vector<char>, char>, char> > q;
static VVII c;
//function
int main(){
  REP(i, 8){
    clear[i] = i;
  }
  move[0].PB(1);
  move[0].PB(4);
  move[1].PB(0);
  move[1].PB(2);
  move[1].PB(5);
  move[2].PB(1);
  move[2].PB(3);
  move[2].PB(6);
  move[3].PB(2);
  move[3].PB(7);
  move[4].PB(0);
  move[4].PB(5);
  move[5].PB(1);
  move[5].PB(4);
  move[5].PB(6);
  move[6].PB(2);
  move[6].PB(5);
  move[6].PB(7);
  move[7].PB(3);
  move[7].PB(6);
  while(scanf("%d %d %d %d %d %d %d %d", &now[0], &now[1], &now[2], & now[3], &now[4], &now[5], &now[6], &now[7]) != EOF){
    REP(i, 8){
      if(!now[i]){
	b = i;
	break;
      }
    }
    if(now == clear){
      printf("0\n");
      continue;
    }
      ans = cp;
      ans[clear] = 127;
      q.push(pair<pair<vector<char>, char>, char>(pair<vector<char>, char>(now, 0),b));
      c.PB(now);
    while(!q.empty()){
      now = q.front().F.F;
      char a = q.front().F.S;
      b = q.front().S;
      q.pop();
      if(!ans[now] || (ans[now] > a && ans[clear] > a)){
	ans[now] = a;
	if(clear == now){
	  d = ans[now];
	}
      }
      else if(ans[clear] == a){
	break;
      }
      else{
	continue;
      }
      //cout << "a = " << a << " b = " << b << "\n";
      REP(i, move[b].size()){
	char tmp; 
	tmp = move[b][i];
	
	swap(now[tmp], now[b]);
	if(!binary_search(c.begin(), c.end(), now)){
	  c.PB(now);
	  q.push(pair<pair<vector<char>, char>, char>(pair<vector<char>, char>(now, a + 1), tmp));
	}
	swap(now[tmp], now[b]);
      }
    }
        
    
    printf("%d\n", d);
  }
  return 0;
}

Compiler output:
a.cc:42:8: error: 'VVII' does not name a type; did you mean 'VVI'?
   42 | static VVII c;
      |        ^~~~
      |        VVI
a.cc: In function 'int main()':
a.cc:48:3: error: reference to 'move' is ambiguous
   48 |   move[0].PB(1);
      |   ^~~~
In file included from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:4:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
In file included from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:61,
                 from /usr/include/c++/14/bits/stl_algobase.h:64:
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:38:30: note:                 'std::vector<std::vector<char> > move'
   38 | static vector<vector<char> > move(8);
      |                              ^~~~
a.cc:49:3: error: reference to 'move' is ambiguous
   49 |   move[0].PB(4);
      |   ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:38:30: note:                 'std::vector<std::vector<char> > move'
   38 | static vector<vector<char> > move(8);
      |                              ^~~~
a.cc:50:3: error: reference to 'move' is ambiguous
   50 |   move[1].PB(0);
      |   ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:38:30: note:                 'std::vector<std::vector<char> > move'
   38 | static vector<vector<char> > move(8);
      |                              ^~~~
a.cc:51:3: error: reference to 'move' is ambiguous
   51 |   move[1].PB(2);
      |   ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:38:30: note:                 'std::vector<std::vector<char> > move'
   38 | static vector<vector<char> > move(8);
      |                              ^~~~
a.cc:52:3: error: reference to 'move' is ambiguous
   52 |   move[1].PB(5);
      |   ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:38:30: note:                 'std::vector<std::vector<char> > move'
   38 | static vector<vector<char> > move(8);
      |                              ^~~~
a.cc:53:3: error: reference to 'move' is ambiguous
   53 |   move[2].PB(1);
      |   ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:38:30: note:                 'std::vector<std::vector<char> > move'
   38 | static vector<vector<char> > move(8);
      |                              ^~~~
a.cc:54:3: error: reference to 'move' is ambiguous
   54 |   move[2].PB(3);
      |   ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:38:30: note:                 'std::vector<std::vector<char> > move'
   38 | static vector<vector<char> > move(8);
      |                              ^~~~
a.cc:55:3: error: reference to 'move' is ambiguous
   55 |   move[2].PB(6);
      |   ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:38:30: note:                 'std::vector<std::vector<char> > move'
   38 | static vector<vector<char> > move(8);
      |                              ^~~~
a.cc:56:3: error: reference to 'move' is ambiguous
   56 |   move[3].PB(2);
      |   ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)'
  353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
      | ^~~~
/usr/include/c++/14/bits/stl_algobase.h:675:5: note:                 'template<class _II, class _OI>