Language: C++

#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

vector<vector<int> >vec;
vector<int>v;
int n,m,l,d,cur,dep,mi,de;
char b;

void go(){
    cur=m,dep=0;
    while(dep<d){
        for(int i=0;i<vec[dep].size();i++){
            if(vec[dep][i]==cur){
                cur=vec[dep][i]+1;
                break;
            }
            if(vec[dep][i]+1==cur){
                cur=vec[dep][i];
                break;
            }
        }
        dep++;
    }
}

int main(){
    while(cin>>n,n){
        vec.clear();
        cin>>m>>l>>d;
        for(int i=0;i<d;i++){
            vec.push_back(v);
            for(int j=1;j<n;j++){
                cin>>b;
                if(b=='1')
                    vec[i].push_back(j);
            }
        }
        go();
        if(cur==l){
            cout<<0<<endl;
            goto ne;
        }
        mi=99,de=0;
        for(int i=1;i<n;i++){
            for(int j=0;j<d;j++){
                if(find(vec[j].begin(),vec[j].end(),i-1)!=vec[j].end())continue;
                if(find(vec[j].begin(),vec[j].end(),i)!=vec[j].end())continue;
                if(find(vec[j].begin(),vec[j].end(),i+1)!=vec[j].end())continue;
                vec[j].push_back(i);
                go();
                if(cur==l){
                    if(abs(cur-m)<abs(mi-m)){
                        mi=i;
                        de=j;
                    }
                }
                vec[j].pop_back();
            }
        }
        if(mi!=99)cout<<de<<" "<<mi<<endl;
        else cout<<1<<endl;
    ne:;
    }
    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:24: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int)'
   48 |                 if(find(vec[j].begin(),vec[j].end(),i-1)!=vec[j].end())continue;
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:48:24: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   48 |                 if(find(vec[j].begin(),vec[j].end(),i-1)!=vec[j].end())continue;
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:49:24: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int&)'
   49 |                 if(find(vec[j].begin(),vec[j].end(),i)!=vec[j].end())continue;
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:49:24: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   49 |                 if(find(vec[j].begin(),vec[j].end(),i)!=vec[j].end())continue;
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:50:24: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int)'
   50 |                 if(find(vec[j].begin(),vec[j].end(),i+1)!=vec[j].end())continue;
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:50:24: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   50 |                 if(find(vec[j].begin(),vec[j].end(),i+1)!=vec[j].end())continue;
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~