Language: C++

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <deque>
#include <tuple>
using namespace std;

typedef pair<int,int> P;
typedef tuple<int,int,int,int> T;//B,x,y
typedef tuple<int,int,int,int> T4;//d,B,x,y
vector<P> B;
int board[15][20];

int main(){
    fill(board[0],board[20],-1);
    int ox,oy;
    for(int i=0;i<19;i++){
        for(int j=0;j<15;j++){
            char c;
            cin>>c;
            if(c=='O'){
                oy=i; ox=j;
            }else if(c=='X'){
                board[j][i]=B.size();
                B.emplace_back(j,i);
            }
        }
    }
    /*
    for(int i=0;i<20;i++){
        for(int j=0;j<15;j++){
            if(board[j][i]==-1) cout<<'.';
            else cout<<board[j][i];
        }
        cout<<endl;
    }
    */
    map<T,int> M;
    deque<T> que;
    que.emplace_back(0,(1<<B.size())-1,ox,oy);
    int ans = 10000;
    while(!que.empty()){
        int d,bb,x,y;
        tie(d,bb,x,y)=que.front(); que.pop_front();
        // cout<<d<<' '<<bb<<' '<<x<<' '<<y<<endl;
        if(y>=18){
            cout<<d<<endl;
            return 0;
        }
        if(x<0||x==15) continue;
        for(int dy=-1;dy<=1;dy++){
            for(int dx=-1;dx<=1;dx++){
                if(!dx&&!dy)continue;
                if(x+dx<0||x+dx>=15) continue;
                if(y+dy<0||y+dy>=19) continue;
                if(board[x+dx][y+dy]==-1) continue;
                else{
                    if(bb&(1<<board[x+dx][y+dy])){
                        int l=2;
                        int bbb=bb^(1<<board[x+dx][y+dy]);
                        while(true){
                            if(x+dx*l<0||x+dx*l>=15||y+dy*l<0||y+dy*l>=19){
                                break;
                            }else{
                                if(board[x+dx*l][y+dy*l]==-1){
                                    break;
                                }else{
                                    if((1<<board[x+dx*l][y+dy*l])&bbb){
                                        bbb^=1<<board[x+dx*l][y+dy*l];
                                        l++;
                                        continue;
                                    }else{
                                        break;
                                    }
                                }
                            }
                        }
                        if(M.find(T(bbb,x+dx*l,y+dy*l))==M.end()){
                            M[T(bbb,x+dx*l,y+dy*l)]=d+1;
                            que.emplace_back(d+1,bbb,x+dx*l,y+dy*l);
                        }else if(M[T(bbb,x+dx*l,y+dy*l)]>d+1){
                            M[T(bbb,x+dx*l,y+dy*l)]=d+1;
                            que.emplace_back(d+1,bbb,x+dx*l,y+dy*l);
                        }
                    }
                }
            }
        }

    }
    cout<<-1<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:79:54: error: no matching function for call to 'std::tuple<int, int, int, int>::tuple(int&, int, int)'
   79 |                         if(M.find(T(bbb,x+dx*l,y+dy*l))==M.end()){
      |                                                      ^
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/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/tuple:1646:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<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}]'
 1646 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1646:9: note:   template argument deduction/substitution failed:
a.cc:79:54: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   79 |                         if(M.find(T(bbb,x+dx*l,y+dy*l))==M.end()){
      |                                                      ^
/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>::_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}]'
 1634 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1634:9: note:   template argument deduction/substitution failed:
a.cc:79:54: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   79 |                         if(M.find(T(bbb,x+dx*l,y+dy*l))==M.end()){
      |                                                      ^
/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>::_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}]'
 1623 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1623:9: note:   template argument deduction/substitution failed:
a.cc:79:54: note:   mismatched types 'const std::tuple<_Elements ...>' and 'int'
   79 |                         if(M.find(T(bbb,x+dx*l,y+dy*l))==M.end()){
      |                                                      ^
/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>::_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}]'
 1611 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1611:9: note:   template argument deduction/substitution failed:
a.cc:79:54: note:   mismatched types 'const std::tuple<_Elements ...>' and 'int'
   79 |                         if(M.find(T(bbb,x+dx*l,y+dy*l))==M.end()){
      |                                                      ^
/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}]'
 1603 |         tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:1603:9: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   cannot convert 'bbb' (type 'int') to type 'std::allocator_arg_t'
   79 |                         if(M.find(T(bbb,x+dx*l,y+dy*l))==M.end()){
      |                                     ^~~
/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}]'
 1598 |         tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:1598:9: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   cannot convert 'bbb' (type 'int') to type 'std::allocator_arg_t'
   79 |                         if(M.find(T(bbb,x+dx*l,y+dy*l))==M.end()){
      |                                     ^~~
/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>::_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}]'
 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>::_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}]'
 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>::_TCC<_Valid>::__is_explicitly_constructible<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}]'
 1573 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1573:9: note:   candidate expects 6 arguments, 3 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>::_TCC<_Valid>::__is_implicitly_constructible<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}]'
 1565 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1565:9: note:   candidate expects 6 arguments, 3 provided
/usr/include/c++/14/tuple:1559:9: note: candidate: 'template<class _Alloc, typename std::enable_if<std::tuple<int, int, int, int>::_TCC<((bool)std::is_object<_Alloc>::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}]'
 1559 |         tuple(allocator_arg_t __tag, const _Alloc& __a)
      |         ^~~~~
/usr/include/c++/14/tuple:1559:9: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/14/tuple:1552:9: note: candidate: 'template<class _Alloc, typename std::enable_if<std::tuple<int, int, int, int>::_TCC<((bool)std::is_object<_Alloc>::value)