Problem:
F： 01 文字列と窓 (Binary String with Slit)
問題
文字の種類が
0
と
1
のみからなる文字列
S
が与えられます。以下の操作を繰り返すことで、
S
を
T
に変えたいです。
文字列
S
中の最も右側に登場する
1
を含むように、幅
2
のスリットを置く。スリット内には連続した
2
文字を必ず含まなければならない。つまり、文字列の端
1
文字のみを含むように置くことはできない。
2
通り置ける場合も考えられるが、この場合はどちらの方法で置いても構わない。
スリット中の
2
文字を
2
桁の二進数と捉えるとき、元の数値との差の絶対値が
1
になるようにスリット中の文字を変更する。ただし、スリット中の文字の両方が
0
になってはならない。つまり、変更後のスリット内の数値は
1
から
3
までのいずれかとなる。
クエリが
Q
回与えられます。
i
番目のクエリで
1
を少なくとも一つ含む文字列
S_i, T_i
が与えられるので、
S_i
を
T_i
に変えるために必要な操作回数の最小値を、それぞれのクエリについて求めてください。
入力形式
Q
S_1
T_1
...
S_Q
T_Q
1
行目では、クエリの個数
Q
が与えられる。
2
行目以降
Q
行は、クエリが与えられる。
i+1
行目では
S_i
と
T_i
が空白区切りで与えられる。
制約
1 \leq Q \leq 10^5
2 \leq |S_i| = |T_i| \leq 50
S_i, T_i
は
0
と
1
のみからなる文字列である。
S_i, T_i
はともに
1
を少なくとも 1 つ含む文字列である。
出力形式
出力は
Q
行からなる。
i
行目には、
i
番目のクエリに対する結果を出力せよ。
入力例1
4
101 110
101 101
1010 1101
11011001 10010101
出力例1
1
0
3
12
1
個目のクエリでは、
S =
101
を
T =
110
と一致させるために必要な操作回数の最小値を求める必要があります。以下の画像のように、
S
の中に登場する
1
の中で最も右にあるものが含まれるようにスリットを置き、スリット中の文字列を書き換えることで
1
回の操作で
S
と
T
を一致させることができます。
2
個目のクエリでは、はじめから
S
と
T
が一致しているため、操作の必要がありません。
3
個目のクエリについて、以下の画像のように文字列を変更させると
3
回の操作で
S
と
T
を一致させることができます。

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

int solve(string S, string T) {
    if (S == T) return 0;
    int idx1 = -1;
    int idx2 = -1;
    for (int i = 0; i < (int)S.size(); i++) {
        if (S[i] == '1' && T[i] == '1') idx1 = i;
        if (S[i] != T[i]) break;
        idx2 = i;
    }

    // Calculate
    int lastS = -1;
    int lastT = -1;
    for (int i = (int)S.size() - 1; i >= idx1 + 1; i--) {
        if (S[i] == '1') { lastS = i; break; }
    }
    for (int i = (int)T.size() - 1; i >= idx1 + 1; i--) {
        if (T[i] == '1') { lastT = i; break; }
    }
    // cout << idx << " " << lastS << " " << lastT << endl;
    if (lastS == -1) return lastT - idx1;
    if (lastT == -1) return lastS - idx1;
    return lastS + lastT - 2 * (idx2 + 1);
}

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    int Q;
    string S, T;

    // Start
    cin >> Q;
    for (int i = 1; i <= Q; i++) {
        cin >> S >> T;
        cout << solve(S, T) << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3448
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (int i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	cin>>t;
	rep(i,t) solve();
}

void solve(){
	string S,T;
	cin>>S>>T;
	int N=S.size();
	int L=0,R=0,X=INF;
	rep(i,N){
		if(S[i]=='1') L=i;
		if(T[i]=='1') R=i;
		if(S[i]!=T[i]&&X==INF) X=i;
	}
	if(X==INF) cout<<"0\n";
	else if(X<min(L,R)) cout<<L+R-2*X<<"\n";
	else cout<<abs(L-R)<<"\n";
}
accuracy: 1
time_ms: 50
memory_kb: 3448
final_rank: 3

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> K;
	while (K--) {
		string s, t;
		cin >> s >> t;
		int b = 0, c = 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '1')b = i;
			if (t[i] == '1')c = i;
		}
		int ans = 0;
		while (s != t) {
			if (b > c) {
				b--;
				ans++;
				s[b] = '1';
				s[b + 1] = '0';
			}
			else if (c > b) {
				c--;
				ans++;
				t[c] = '1';
				t[c + 1] = '0';
			}
			else {
				ans += 2;
				b--, c--;
				s[b] = t[c] = '1';
				s[b + 1] = t[c + 1] = '0';
			}
		}
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 150
memory_kb: 3220
final_rank: 6

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 55

int length;
char S[NUM],T[NUM];

void func(){

	scanf("%s %s",S,T);

	for(length = 0; S[length] != '\0'; length++);

	int diff_loc = -1;

	for(int i = 0; i < length; i++){

		if(S[i] != T[i]){
			diff_loc = i;
			break;
		}
	}

	if(diff_loc == -1){

		printf("0\n");
		return;
	}

	int R1_S,R1_T;

	for(R1_S = length-1; R1_S >= 0 && S[R1_S] == '0'; R1_S--);
	for(R1_T = length-1; R1_T >= 0 && T[R1_T] == '0'; R1_T--);

	if(R1_S < diff_loc){

		printf("%d\n",R1_T-R1_S);
		return;
	}
	if(R1_T < diff_loc){

		printf("%d\n",R1_S-R1_T);
		return;
	}
	if(R1_S == diff_loc){

		printf("%d\n",R1_T-R1_S);
		return;
	}
	if(R1_T == diff_loc){

		printf("%d\n",R1_S-R1_T);
		return;
	}

	printf("%d\n",(R1_S-diff_loc)+R1_T-diff_loc);
}

int main(){

	int num_query;
	scanf("%d",&num_query);

	for(int loop = 0; loop < num_query; loop++){

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3200
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-11;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    string s, t;
    int m;
    cin >> m;
    REP(k,m){
        cin >> s >> t;
        int n=s.size(), l=-1;
        REP(i,n){
            if(s[i]!=t[i]){
                l = i;
                break;
            }
        }
        if(l<0){
            cout << 0 << endl;
        }
        else{
            int ans = 0;
            REPR(r,n-1) {
                if(s[r]=='1'){
                    ans += abs(r-l);
                    break;
                }
            }
            REPR(r,n-1){
                if(t[r]=='1'){
                    ans += abs(r-l);
                    break;
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 370
memory_kb: 3212
final_rank: 10

code_snippet: /*  -*- coding: utf-8 -*-
 *
 * 2894.cc: Binary String with Slit
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;

/* typedef */

/* global variables */

char s[MAX_N + 2], t[MAX_N + 2];

/* subroutines */

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    scanf("%s%s", s, t);

    int n = strlen(s), k = 0;
    while (k < n && s[k] == t[k]) k++;
    if (k >= n) {
      puts("0");
      continue;
    }

    int se = n - 1, te = n - 1;
    while (s[se] == '0') se--;
    while (t[te] == '0') te--;
    //printf("n=%d, k=%d, se=%d, te=%d\n", n, k, se, te);

    int cnt = 0;
    if (se > k) cnt += se - k, se = k;
    cnt += abs(te - se);
    printf("%d\n", cnt);
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3232
final_rank: 2

code_snippet: #include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;






int main(){
    ll q;
    cin>>q;
    while(q--){
        ll fd=E,mx=-1,mx2=-1;
        string s,t;
        cin>>s>>t;
        if(s==t){cout<<0<<endl; continue;}
        for(int i=0;i<s.size();i++){
            if(s[i]!=t[i]){fd=min(fd,(ll)i);}
            if(s[i]=='1'){mx=max(mx,(ll)i);}
            if(t[i]=='1'){mx2=max(mx2,(ll)i);}
        }
        cout<<abs(fd-mx)+abs(mx2-fd)<<endl;
    }
    
    
    
    return 0;
}
accuracy: 1
time_ms: 630
memory_kb: 3220
final_rank: 19

code_snippet: #include<iostream>
#include<cassert>
#include<vector>
#include<map>
#include<string>

using namespace std;

typedef long long ll;

ll binary_to_ll(string s, int n){
    ll a = 0LL;
    for(int j=0;j<n;j++) a |= (ll(s[j] == '1') << (n-1-j));
    return a;
}

int get_lsb(ll a, int n){
    int lsb = 0;
    while(lsb < n && ((a >> lsb) & 1LL) == 0LL) lsb++;
    return lsb;
}

void up_lsb(ll *a, int *lsb){
    if((*a >> (*lsb+1)) & 1LL){
        // 11→10
        *a ^= (1LL << (*lsb));
    }else{
        // 01→10
        *a ^= (3LL << (*lsb));
    }
    
    (*lsb)++;
}

int solve(string s, string t){
    int n = int(s.length());
    ll a = binary_to_ll(s, n), b = binary_to_ll(t, n);
    int lsba = get_lsb(a, n), lsbb = get_lsb(b, n);
    int d = 0;
    while(a != b){
        if(lsba < lsbb){
            up_lsb(&a, &lsba);
        }else{
            up_lsb(&b, &lsbb);
        }
        d++;
    }
    return d;
}

int main(){
    int n;
    cin >> n;
    string s,t;
    for(int i=0;i<n;i++){
        cin >> s >> t;
        cout << solve(s,t) << endl;
    }
}
accuracy: 1
time_ms: 370
memory_kb: 3216
final_rank: 11

code_snippet: #include<iostream>
#include<cassert>
#include<vector>
#include<map>
#include<string>

using namespace std;

typedef long long ll;

int get_lsb(ll a, int n){
    int lsb = 0;
    while(lsb < n && ((a >> lsb) & 1LL) == 0LL) lsb++;
    return lsb;
}

void up_lsb(ll *a, int *lsb){
    if((*a >> (*lsb+1)) & 1LL){
        // 11→10
        *a ^= (1LL << (*lsb));
    }else{
        // 01→10
        *a ^= (3LL << (*lsb));
    }
    
    (*lsb)++;
}

int solve(string s, string t){
    if(s == t) return 0;

    int n = int(s.length());
    ll a = 0LL, b = 0LL;
    for(int j=0;j<n;j++) a |= (ll(s[j] == '1') << (n-1-j));
    for(int j=0;j<n;j++) b |= (ll(t[j] == '1') << (n-1-j));

    int lsba = get_lsb(a, n), lsbb = get_lsb(b, n);

    int d = 0;
    while(d <= 100){
        if(lsba < lsbb){
            up_lsb(&a, &lsba);
        }else{
            up_lsb(&b, &lsbb);
        }
        d++;
        if(a == b) return d;
    }

    return 0;
}

int main(){
    int n;
    cin >> n;
    string s,t;
    for(int i=0;i<n;i++){
        cin >> s >> t;
        cout << solve(s,t) << endl;
    }
}
accuracy: 1
time_ms: 370
memory_kb: 3216
final_rank: 11

code_snippet: #include <iostream>
#include <string>
using namespace std;

int main() {
	int Q; cin >> Q;
	for (int _ = 0; _ < Q; ++_) {
		int res = 0;
		string S[2]; cin >> S[0] >> S[1];

		if (S[0] == S[1]) {
			cout << 0 << endl;
			continue;
		}

		int n = S[0].size();

		int ichi = 0;
		int zerogawa = 0;
		bool allzero = true;
		for (int i = 0; i < n; ++i) {
			if (S[0][i] != S[1][i]) {
				ichi = i;
				break;
			}
		}
		if (S[0][ichi] == '0') zerogawa = 0;
		else zerogawa = 1;
		for (int i = ichi; i < n; ++i) {
			if (S[zerogawa][i] == '1') allzero = false;
		}

		if (allzero) {
			int first = 0;
			for (int i = ichi; i >= 0; --i) {
				if (S[zerogawa][i] == '1') {
					first = i;
					break;
				}
			}
			ichi = first;
		}

		for (int iter = 0; iter < 2; ++iter) {
			int second = ichi;
			for (int i = ichi; i < n; ++i) {
				if (S[iter][i] == '1') {
					second = i;
				}
			}
			res += second - ichi;
		}
		cout << res << endl;
	}
}
accuracy: 1
time_ms: 390
memory_kb: 3216
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int q;
int sv[101];
int tv[101];

int main(void){
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		string s,t;
		cin >> s;
		cin >> t;
		for(int j=0;j<s.size();j++){
			if(s[j]=='0'){
				sv[j]=0;
			}else{
				sv[j]=1;
			}
			if(t[j]=='0'){
				tv[j]=0;
			}else{
				tv[j]=1;
			}
		}
		int ans=0;
		int v=0;
		for(int j=s.size()-1;j>=0;j--){
			bool sa=true;
			for(int k=0;k<s.size();k++){
				if(sv[k]!=tv[k]){
					sa=false;
					break;
				}
			}
			if(sa)break;
			if(sv[j]==1)v=v|1;
			if(tv[j]==1)v=v|2;
			if(v&1){
				if(sv[j-1]==0){
					sv[j]=0;
					sv[j-1]=1;
				}else{
					sv[j-1]=1;
					sv[j]=0;
				}
				ans++;
			}
			if(v&2){
				if(tv[j-1]==0){
					tv[j]=0;
					tv[j-1]=1;
				}else{
					tv[j-1]=1;
					tv[j]=0;
				}
				ans++;
			}
			//printf("%d %d\n",v,ans);
		}
		printf("%d\n",ans);
	}
	return 0;
}
accuracy: 1
time_ms: 430
memory_kb: 3368
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#define inf 10000
using namespace std;

int a, b, c, q, x, y;
string s, t;

int main() {
  cin >> q;
  while(q--) {
    a = inf;
    cin >> s >> t;
    for(int i = 0; i < s.size(); ++i) {
      if(s[i] != t[i]) a = min(a, i);
      if(s[i] == '1') b = i;
      if(t[i] == '1') c = i;
    }
    if(a == inf)
      cout << 0 << endl;
    else {
      x = max(b - a, 0);
      y = c - min(a, b);
      if(y < 0) y *= -1;
      cout << x + y << endl;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 3204
final_rank: 8

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://onlinejudge.u-aizu.ac.jp/services/room.html#ACPC2018Day3/problems/F>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

void solve(){
    int Q; cin >> Q;
    while(Q--){
        ll cnt = 0;
        string S,T; cin >> S >> T;
        int x = (int)S.length()-1;
        while(x>=0){
            if(S[x]=='1') break;
            x--;
        }
        int y = (int)T.length()-1;
        while(y>=0){
            if(T[y]=='1') break;
            y--;
        }
        int dif = x;
        for(int i = 0; i < S.length();i++){
            if(S[i] == T[i]) continue;
            dif = i;
            break;
        }
        cnt = abs(x-dif) + abs(y-dif);
        cout << cnt << endl;
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 3200
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

using int64 = long long;


int main() {
  int Q;
  cin >> Q;
  while(Q--) {
    string S, T;
    cin >> S >> T;

    if(S == T) {
      cout << 0 << endl;
      continue;
    }

    // はやすばあい
    int itti = 0;
    for(int i = 0; i < S.size(); i++) {
      if(S[i] == T[i]) {
        itti = i + 1;
      } else {
        break;
      }
    }


    int last_one = -1;
    for(int i = S.size() - 1; i >= 0; i--) {
      if(S[i] == '1') {
        last_one = i;
        break;
      }
    }

    int cost = 0;
    cost += max(0, last_one - itti);
    int last_uku = -1;
    for(int i = T.size() - 1; i >= last_uku; i--) {
      if(T[i] == '1') {
        last_uku = i;
        break;
      }
    }
    if(last_uku < itti && last_one >= itti) {
      cost += itti - last_uku;
    } else if(last_one < itti) cost += last_uku - last_one;
    else cost += last_uku - itti;
    cout << cost << endl;
  }
}
accuracy: 1
time_ms: 370
memory_kb: 3208
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define loop(i, a, n) for (int i = a; i < (int) n; i++)
#define rep(i, n) loop(i, 0, n)
using namespace std;

int main() {
  int N;
  cin >> N;
  string s, t;
  while (cin >> s >> t) {
    if (s == t) {
      cout << 0 << endl;
      continue;
    }
    int n = s.size();
    int rs = s.rfind('1');
    int rt = t.rfind('1');
    int l = n - 1;
    rep(i, n) {
      if (s[i] != t[i]) {
        l = i;
        break;
      }
    }
    // cout << l << " " << rs << " " << rt << endl;
    int ans;
    if (rt < l) {
      ans = rs - rt;
    } else if (rs < l) {
      ans = rt - rs;
    } else {
      ans = abs(rs - l) + abs(rt - l);
    }
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 430
memory_kb: 3208
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <map>
#include <cmath>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    string s,t;
    int q;
    cin >> q;
    rep(zz,q){
        cin >> s >> t;
        int n = s.size();
        bool ok = 1;
        bool flag = 0;
        bool sflag = 0;
        bool tflag = 0;
        int sr = 0;
        int ssr = 0;
        int tr = 0;
        int out = 0;
        rep(i,n){
            if(s[i]!=t[i]&&ok){
                out = i;
                ok = 0;
                if(s[i]=='1'){
                    flag = 1;
                }
            }else if(!ok){
                if(s[i]!='0'){
                    sflag = 1;
                    sr = i;
                }
                if(t[i]!='0'){
                    tflag = 1;
                    tr = i;
                }
            }
        }
        //cout << out << endl;
        rep(i,out){
            if(s[i]!='0'){
                ssr = i;
            }
        }
        // cout << ssr << endl;
        // cout << flag << " " << sflag << " " << tflag << endl;
        if(ok){
            cout << 0 << endl;
            continue;
        }
        int ans = 0;
        if(flag){
            if(sflag&tflag){
                ans += sr-out;
                ans += tr-out;
            }else if(sflag&(!tflag)){
                ans += sr-ssr;
            }else if((!sflag)&tflag){
                ans += tr-out;
            }else{
                ans = out-ssr;
            }
        }else{
            if(sflag&tflag){
                ans += sr-out;
                ans += tr-out;
            }else if(sflag&(!tflag)){
                ans += sr-out;
            }else if((!sflag)&tflag){
                ans += tr-ssr;
            }else{
                ans += out-ssr;
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 330
memory_kb: 3220
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

void solve(){
    int N;
    string S,T;
    cin>>S>>T;
    N=S.size();
    int pos;
    for(int i=N-1;i>=0;i--)if(S[i]=='1'){pos=i;break;};

    int uku=-1;
    rep(i,N)if(S[i]!=T[i]){uku=i;break;}
    if(uku==-1){
        cout<<0<<endl;
        return;
    }

    int ans=0;
    if(uku<=pos){
        ans+=pos-uku;
        pos=uku;
    }

    S[pos]='1';
    for(int i=pos+1;i<N;i++)S[i]='0';

    int beet=-1;
    rep(i,N)if(S[i]!=T[i])beet=i;
    if(beet==-1);
    else if(pos<beet){
        ans+=beet-pos;
    }
    else if(pos==beet&&T[pos]=='0'){
        int latte;
        for(int i=pos-1;i>=0;i--)if(S[i]=='1'){latte=i;break;}
        ans+=pos-latte;
    }
    cout<<ans<<endl;
}


signed main(){
    int Q;cin>>Q;
    while(Q--)solve();

    return 0;
}
accuracy: 1
time_ms: 510
memory_kb: 3204
final_rank: 18

code_snippet: #include <iostream>
#include <string>
using namespace std;

int main() {
    int Q; cin >> Q;
    for (int _ = 0; _ < Q; ++_) {
        int res = 0;
        string S[2]; cin >> S[0] >> S[1];

        if (S[0] == S[1]) {
            cout << 0 << endl;
            continue;
        }
        
        int n = S[0].size(); 

        int ichi = 0;
        int zerogawa = 0;
        bool allzero = true;
        for (int i = 0; i < n; ++i) {
            if (S[0][i] != S[1][i]) {
                ichi = i;
                break;
            }
        }
        if (S[0][ichi] == '0') zerogawa = 0;
        else zerogawa = 1;
        for (int i = ichi; i < n; ++i) {
            if (S[zerogawa][i] == '1') allzero = false;
        }

        if (allzero) {
            int first = 0;
            for (int i = ichi; i >= 0; --i) {
                if (S[zerogawa][i] == '1') {
                    first = i;
                    break;
                }
            }
            ichi = first;
        }

        for (int iter = 0; iter < 2; ++iter) {
            int second = ichi;
            for (int i = ichi; i < n; ++i) {
                if (S[iter][i] == '1') {
                    second = i;
                }
            }
            res += second - ichi;
        }
        cout << res << endl;
    }
}
accuracy: 1
time_ms: 390
memory_kb: 3208
final_rank: 13

code_snippet: #include<iostream>
#include<string>
#include<vector>

using namespace std;
using ll = long long;
#define FOR(i,k,n) for(ll (i)=(k);(i)<(n);(i)++)
#define REP(i,n) FOR((i),0,(n))


int Q;
vector<pair<string, string>> s;

void input() {
	cin >> Q;
	string a, b;
	REP(i, Q) {
		cin >> a >> b;
		s.push_back({ a,b });
	}
}

int action(string s, string t) {
	int x = s.size() - 1;
	while (s[x] != '1')x--;
	int y = t.size() - 1;
	while (t[y] != '1')y--;

	int z = -1;
	REP(i, s.size()){
		if (s[i] != t[i]) {
			z = i;
			break;
		}
	}
	if (z == -1)return 0;
	return abs(x - z) + abs(y - z);
}

int main() {
	input();
	for (auto p : s) {
		cout << action(p.first, p.second) << endl;
	}
	//cin >> Q;
}
accuracy: 1
time_ms: 390
memory_kb: 26360
final_rank: 20

code_snippet: #include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;






int main(){
    ll q;
    cin>>q;
    while(q--){
        ll fd=E,mx=-1,mx2=-1;
        string s,t;
        cin>>s>>t;
        if(s==t){cout<<0<<endl; continue;}
        for(int i=0;i<s.size();i++){
            if(s[i]!=t[i]){fd=min(fd,(ll)i);}
            if(s[i]=='1'){mx=max(mx,(ll)i);}
            if(t[i]=='1'){mx2=max(mx2,(ll)i);}
        }
        cout<<abs(fd-mx)+abs(mx2-fd)<<endl;
    }
    
    
    
    return 0;
}
accuracy: 1
time_ms: 430
memory_kb: 3208
final_rank: 15