Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstring>
- #include <climits>
- #include <queue>
- using namespace std;
- ifstream cin("base3.in");
- ofstream cout("base3.out");
- #define inf 1<<30
- const int maxn=20000;
- queue<int> g;
- int lg[maxn],viz[maxn],lung[3];
- char numb[maxn];
- int main()
- {
- for(int i=0;i<maxn;++i) lg[i]=inf;
- for(int i=0;i<3;++i){
- cin>>numb;
- lung[i]=strlen(numb);
- for(int k=0;k<lung[i];++k)
- if(numb[k]=='1'){
- int aux=abs(lung[i]-2*k-1);
- if(!viz[aux]){
- lg[aux]=lung[i];
- viz[aux]=1;
- g.push(aux);
- }
- }
- }
- while(!g.empty()){
- int xd=g.front();
- g.pop();
- for(int i=0;i<3;++i){
- int x=abs(xd-lung[i]);
- if(lg[x]>lg[xd]+lung[i]){
- lg[x]=lg[xd]+lung[i];
- if(!viz[x])
- g.push(x),viz[x]=1;
- }
- }
- viz[xd]=0;
- }
- cout<<((lg[0]!=inf)?lg[0]:0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement