P2133
90分MLE
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
struct node
{
int a[6],x;
}y;
queue<node> r;
inline bool pd(node z)
{
string s;
for(int i=0;i<6;i++){
s+=z.a[i]+'0';
}
return s==s2;
}
int main()
{
cin>>s1>>s2;
for(int i=0;i<6;i++){
y.a[i]=s1[i]-'0';
}
y.x=0;
r.push(y);
bool f=0;
while(!r.empty()){
node z=r.front();
r.pop();
if(pd(z)){
if(!f) f=1;
else{
cout<<z.x;
return 0;
}
}
z.x++;
for(int i=0;i<5;i++){
swap(z.a[i],z.a[i+1]);
r.push(z);
swap(z.a[i],z.a[i+1]);
}
}
return 0;
}