Language: C++

/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
signed main(){
	string s,t;
	cin>>s>>t;
	t+=t+t;
	vi a;
	a.pb(-10000);
	rep(i,t.size())if(t[i]=='1')a.pb(i);
	a.pb(t.size()+10000);
	if(a.size()==2){
		if(s.find('1')==string::npos)cout<<0<<endl;
		else cout<<-1<<endl;
		return 0;
	}
	int out=inf;
	rep(i,s.size()*2){
		vvi in;
		int co=0;
		rep(j,s.size())if(s[j]-t[i+j]){
			co++;
			int L=min(i+j,s.size()+j),R=max(i+j,s.size()+j);
			int r=lower_bound(all(a),i+j)-a.begin(),l=r-1;
			r=a[r];l=a[l];
			if((L<=l&&l<=R)||(L<=r&&r<=R));
			else in.pb({L-l,r-R});
		}
		int mi=inf,ma=0;
		sort(all(in));
		rep(i,in.size())rep(j,2)assert(0<=in[i][0]&&in[i][1]<=7000),assert(0<=in[i][0]&&in[i][1]<=7000);
		for(int j=(int)in.size()-1;j>=0;j--){
			cmin(mi,ma+in[j][0]);
			cmax(ma,in[j][1]);
		}
		if(mi==inf)mi=0;
		cmin(mi,ma);
		cmin(out,co+2*mi+abs((int)s.size()-i));
	}
	cout<<out<<endl;
}















Compiler output:
a.cc: In function 'int main()':
a.cc:99:34: error: no matching function for call to 'min(ll, long long unsigned int)'
   99 |                         int L=min(i+j,s.size()+j),R=max(i+j,s.size()+j);
      |                               ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 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:26:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:99:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   99 |                         int L=min(i+j,s.size()+j),R=max(i+j,s.size()+j);
      |                               ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:29:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:99:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   99 |                         int L=min(i+j,s.size()+j),R=max(i+j,s.size()+j);
      |                               ~~~^~~~~~~~~~~~~~~~
a.cc:102:38: error: 'R' was not declared in this scope
  102 |                         if((L<=l&&l<=R)||(L<=r&&r<=R));
      |                                      ^
a.cc:103:35: error: no matching function for call to 'std::vector<std::vector<long long int> >::push_back(<brace-enclosed initializer list>)'
  103 |                         else in.pb({L-l,r-R});
      |                              ~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:27:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; value_type = std::vector<long long int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::vector<long long int> >::value_type&' {aka 'const std::vector<long long int>&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; value_type = std::vector<long long int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::vector<long long int> >::value_type&&' {aka 'std::vector<long long int>&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~