Language: C++

#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
using namespace std;
string s1,s2;
pair<int,int>p[2001];
#define int long long
main(){
	int ans=1e9;
	cin>>s1>>s2;
	for(int i=0,j=0,k=0;i<s1.size();i++){
		if(s2[i]=='1')j++;
		if(s1[i]=='1')k++;
		if(i==s1.size()-1&&!j&&k){
			cout<<-1<<endl;
			exit(0);
		}
	}

	r(i,s1.size()){
		for(int j=0,k=i;j<s1.size();j++,k++,k=k%(int)s1.size())
			if(s2[k]=='1'){p[i].fi=j;break;}
		for(int j=0,k=i;j<s1.size();j++,k--){
			if(k==-1)k=(int)s1.size()-1;
			if(s2[k]=='1'){p[i].se=j;break;}
		}
	}

	r(i,s1.size()){
		int l=0,r=0,t=0,xx=0;
		r(j,s1.size()){
			if(s1[j]=='0'&&s2[j]=='1')t++;
			else if(s1[j]=='1'&&s2[j]=='0'){
				l=max(p[j].fi,l);
				r=max(p[j].se,r);
				xx++;
			}
		}

		ans=min(ans,min(l,r)+t+i+xx);

		r(j,s1.size()-1)swap(s1[j],s1[j+1]);
	}

	r(i,s1.size()){
		int l=0,r=0,t=0,xx=0;

		r(j,s1.size()){
			if(s1[j]=='0'&&s2[j]=='1')t++;
			else if(s1[j]=='1'&&s2[j]=='0'){
				l=max(p[j].fi,l);
				r=max(p[j].se,r);
				xx++;
			}
		}
		ans=min(ans,min(l,r)+t+i+xx);
		for(int j=s1.size()-1;j>=1;j--)swap(s1[j],s1[j-1]);
	}
    cout<<ans<<endl;
}

Compiler output:
a.cc:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:35:38: error: no matching function for call to 'max(int&, long long int&)'
   35 |                                 l=max(p[j].fi,l);
      |                                   ~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:35:38: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   35 |                                 l=max(p[j].fi,l);
      |                                   ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:35:38: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   35 |                                 l=max(p[j].fi,l);
      |                                   ~~~^~~~~~~~~~~
a.cc:36:38: error: no matching function for call to 'max(int&, long long int&)'
   36 |                                 r=max(p[j].se,r);
      |                                   ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:36:38: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   36 |                                 r=max(p[j].se,r);
      |                                   ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:36:38: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   36 |                                 r=max(p[j].se,r);
      |                                   ~~~^~~~~~~~~~~
a.cc:52:38: error: no matching function for call to 'max(int&, long long int&)'
   52 |                                 l=max(p[j].fi,l);
      |                                   ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:52:38: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   52 |                                 l=max(p[j].fi,l);
      |                                   ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:52:38: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   52 |                                 l=max(p[j].fi,l);
      |                                   ~~~^~~~~~~~~~~
a.cc:53:38: error: no matching function for call to 'max(int&, long long int&)'
   53 |                                 r=max(p[j].se,r);
      |                                   ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:53:38: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   53 |                                 r=max(p[j].se,r);
      |                                   ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:53:38: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   53 |                                 r=max(p[j].se,r);
      |                                   ~~~^~~~~~~~~~~