Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ulli unsigned long long int
#define ldouble  long double
#define pr pair<lli, lli>
#define loop(i,x,n) for(long long int i=x;i<n;i++)
#define loopr(i,x,n) for(lli i=x;i>=n;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define lop(x,m) for(auto &x:m)
#define pb push_back
#define SUM(x) accumulate(x.begin(),x.end(),0LL)
#define py cout<<"YES"<<endl
#define pn cout<<"NO"<<endl
#define ff first
#define ss second
#define M 1000000007
#define vi vector<lli>
#define deb(v) for(auto &x:v){cout<<x<<" ";}cout<<endl;
#define debpr(v)  for(auto x: v){cout<<x.ff<<" "<<x.ss<<"\n";}
#define inp(v,n) for(long long int i=0;i<n;i++){lli x;cin>>x;v.pb(x);}
const char nl = '\n';


#define PI 3.141592653589793238462
#define set_bit __builtin_popcountll
#define MOD1 998244353
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(lli t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ulli t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
lli powerm(lli a, lli b)
{
    lli res = 1;
    while (b > 0)
    {
        if (b & 1 != 0)
            res = (res * a) % M;
        a = (a * a) % M;
        b >>= 1;
    }
    return res;
}
lli power(lli a, lli b)
{
    lli res = 1;
    while (b > 0)
    {
        if (b & 1 != 0)
            res = (res * a) ;
        a = (a * a) ;
        b >>= 1;
    }
    return res;
}


lli inverse(lli a)
{
    return powerm(a, M - 2);
}


bool isprime(lli n){
    int f=0;
    if(n<=1)return false;
    for(lli i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool isperfectsquare(lli x)
{
    if (x >= 0){
        lli sr = sqrt(x);
        return (sr * sr == x) ;
    }
    return false;
}


lli add(lli x,lli y)
{
    return (x%M+y%M+M)%M;
}
 
lli mul(lli x,lli y)
{
    return (((x%M*y%M)%M)+M)%M;
}
 
lli sub(lli x,lli y)
{
    return ((x%M)-(y%M)+M+M)%M;
}
lli lcm(lli a, lli b)
{
    return ((a*b) /__gcd(a, b)) ;
}


lli fact[500001];
lli inv[500001];
void factorial()
{
    fact[0]=1;
    for(int i=1; i<=500000; i++)
    {
        fact[i]=mul(fact[i-1],i);
    }
    inv[500000]=inverse(fact[500000]);
    for(int i=500000; i>0; i--)inv[i-1]=mul(inv[i],i);
}
lli ncr(lli n,lli r)
{
    if(r<0)return 0;
    lli ret=1;
    ret=fact[n];
    ret=mul(ret,inv[r]);
    ret=mul(ret,inv[n-r]);
    return ret;
}


vector<lli> primes,siev(100000+1, 0);
void sieve(){
    for(lli i=2;i<=100000;i++){
        if(siev[i]==0){
            primes.push_back(i);
            for(lli j=i*i;j<=100000;j+=i)  siev[j]=1;
        }
    }
}
bool issorted(vi v){
    loop(i,0,v.size()-1){
        if(v[i]>v[i+1]){
            return false;
        }
    }
    return true;
}


bool ispal(string s){
    lli i=0,j=s.size()-1;
    while(i<j){
        if(s[i]==s[j]){
            i++;
            j--;
        }
        else return false;
    }
    return true;
}
lli logbase(lli a, lli b)
{
    return log2(a) / log2(b);
}
lli countSquares(lli a, lli b)
{
return (floor(sqrtl(b)) - ceil(sqrtl(a)) + 1);
}
vector<vector<int>> dir4 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
vector<vector<int>> dir8 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1},{1,-1},{-1,1},{1,1},{-1,-1}};
lli sqroot(lli n)
{
    lli low = 1, high = n, res;
    while (low <= high)
    {
        lli mid = (low + high) / 2;
        if ((mid * mid) == n)
        {
            res = mid;
            break;
        }
        else if ((mid * mid) > n)
        {
            high = mid - 1;
        }
        else
        {
            res = mid;
            low = mid + 1;
        }
    }
    return res;
}
vi sa,sb;
vector<vector<lli>>dp;
lli slv(lli i,lli j,string &a, string &b, string &c){
    if(i>=a.size()&&j>=b.size()){
        return 0;
    }
    if(i>=a.size()){
        return sb[j];
    }
    if(j>=b.size()){
        return sa[i];
    }
    if(dp[i][j]!=-1)return dp[i][j];
    if(a[i]==c[i+j]&&b[j]==c[i+j]){
        return dp[i][j]=min(slv(i+1,j,a,b,c),slv(i+1,j,a,b,c));
    }
    else if(a[i]==c[i+j]){
        return dp[i][j]=min(slv(i+1,j,a,b,c),1+slv(i,j+1,a,b,c));
    }
    else if(b[j]==c[i+j]){
        return dp[i][j]=min(1+slv(i+1,j,a,b,c),slv(i,j+1,a,b,c));
    }
    else return dp[i][j]=min(1+slv(i+1,j,a,b,c),1+slv(i,j+1,a,b,c));
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    dp=vector<vector<lli>>(a.size()+1,vector<lli>(b.size()+1,-1));
    sa.resize(a.size());
    sb.resize(b.size());
    lli cc=0;
    lli j=c.size()-1;
    loopr(i,a.size()-1,0){
        if(a[i]!=c[j]){
            cc++;
        }
        j--;
        sa[i]=cc;
    }
    cc=0;
    j=c.size()-1;
    loopr(i,b.size()-1,0){
        if(b[i]!=c[j]){
            cc++;
        }
        j--;
        sb[i]=cc;
    }
    cout<<slv(0,0,a,b,c)<<endl;
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("Error.txt", "w", stderr);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    std::cout.unsetf(std::ios::floatfield); 
    std::cout << std::setprecision(10);
    lli t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ulli unsigned long long int
#define ldouble  long double
#define pr pair<lli, lli>
#define loop(i,x,n) for(long long int i=x;i<n;i++)
#define loopr(i,x,n) for(lli i=x;i>=n;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define lop(x,m) for(auto &x:m)
#define pb push_back
#define SUM(x) accumulate(x.begin(),x.end(),0LL)
#define py cout<<"YES"<<endl
#define pn cout<<"NO"<<endl
#define ff first
#define ss second
#define M 1000000007
#define vi vector<lli>
#define deb(v) for(auto &x:v){cout<<x<<" ";}cout<<endl;
#define debpr(v)  for(auto x: v){cout<<x.ff<<" "<<x.ss<<"\n";}
#define inp(v,n) for(long long int i=0;i<n;i++){lli x;cin>>x;v.pb(x);}
const char nl = '\n';


#define PI 3.141592653589793238462
#define set_bit __builtin_popcountll
#define MOD1 998244353
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(lli t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ulli t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
lli powerm(lli a, lli b)
{
    lli res = 1;
    while (b > 0)
    {
        if (b & 1 != 0)
            res = (res * a) % M;
        a = (a * a) % M;
        b >>= 1;
    }
    return res;
}
lli power(lli a, lli b)
{
    lli res = 1;
    while (b > 0)
    {
        if (b & 1 != 0)
            res = (res * a) ;
        a = (a * a) ;
        b >>= 1;
    }
    return res;
}


lli inverse(lli a)
{
    return powerm(a, M - 2);
}


bool isprime(lli n){
    int f=0;
    if(n<=1)return false;
    for(lli i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool isperfectsquare(lli x)
{
    if (x >= 0){
        lli sr = sqrt(x);
        return (sr * sr == x) ;
    }
    return false;
}


lli add(lli x,lli y)
{
    return (x%M+y%M+M)%M;
}
 
lli mul(lli x,lli y)
{
    return (((x%M*y%M)%M)+M)%M;
}
 
lli sub(lli x,lli y)
{
    return ((x%M)-(y%M)+M+M)%M;
}
lli lcm(lli a, lli b)
{
    return ((a*b) /__gcd(a, b)) ;
}


lli fact[500001];
lli inv[500001];
void factorial()
{
    fact[0]=1;
    for(int i=1; i<=500000; i++)
    {
        fact[i]=mul(fact[i-1],i);
    }
    inv[500000]=inverse(fact[500000]);
    for(int i=500000; i>0; i--)inv[i-1]=mul(inv[i],i);
}
lli ncr(lli n,lli r)
{
    if(r<0)return 0;
    lli ret=1;
    ret=fact[n];
    ret=mul(ret,inv[r]);
    ret=mul(ret,inv[n-r]);
    return ret;
}


vector<lli> primes,siev(100000+1, 0);
void sieve(){
    for(lli i=2;i<=100000;i++){
        if(siev[i]==0){
            primes.push_back(i);
            for(lli j=i*i;j<=100000;j+=i)  siev[j]=1;
        }
    }
}
bool issorted(vi v){
    loop(i,0,v.size()-1){
        if(v[i]>v[i+1]){
            return false;
        }
    }
    return true;
}


bool ispal(string s){
    lli i=0,j=s.size()-1;
    while(i<j){
        if(s[i]==s[j]){
            i++;
            j--;
        }
        else return false;
    }
    return true;
}
lli logbase(lli a, lli b)
{
    return log2(a) / log2(b);
}
lli countSquares(lli a, lli b)
{
return (floor(sqrtl(b)) - ceil(sqrtl(a)) + 1);
}
vector<vector<int>> dir4 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
vector<vector<int>> dir8 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1},{1,-1},{-1,1},{1,1},{-1,-1}};
lli sqroot(lli n)
{
    lli low = 1, high = n, res;
    while (low <= high)
    {
        lli mid = (low + high) / 2;
        if ((mid * mid) == n)
        {
            res = mid;
            break;
        }
        else if ((mid * mid) > n)
        {
            high = mid - 1;
        }
        else
        {
            res = mid;
            low = mid + 1;
        }
    }
    return res;
}
vi sa,sb;
vector<vector<lli>>dp;
lli slv(lli i,lli j,string &a, string &b, string &c){
    if(i>=a.size()&&j>=b.size()){
        return 0;
    }
    if(i>=a.size()){
        return sb[j];
    }
    if(j>=b.size()){
        return sa[i];
    }
    if(dp[i][j]!=-1)return dp[i][j];
    if(a[i]==c[i+j]&&b[j]==c[i+j]){
        return dp[i][j]=min(slv(i+1,j,a,b,c),slv(i,j+1,a,b,c));
    }
    else if(a[i]==c[i+j]){
        return dp[i][j]=min(slv(i+1,j,a,b,c),1+slv(i,j+1,a,b,c));
    }
    else if(b[j]==c[i+j]){
        return dp[i][j]=min(1+slv(i+1,j,a,b,c),slv(i,j+1,a,b,c));
    }
    else return dp[i][j]=min(1+slv(i+1,j,a,b,c),1+slv(i,j+1,a,b,c));
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    dp=vector<vector<lli>>(a.size()+1,vector<lli>(b.size()+1,-1));
    sa.resize(a.size());
    sb.resize(b.size());
    lli cc=0;
    lli j=c.size()-1;
    loopr(i,a.size()-1,0){
        if(a[i]!=c[j]){
            cc++;
        }
        j--;
        sa[i]=cc;
    }
    cc=0;
    j=c.size()-1;
    loopr(i,b.size()-1,0){
        if(b[i]!=c[j]){
            cc++;
        }
        j--;
        sb[i]=cc;
    }
    cout<<slv(0,0,a,b,c)<<endl;
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("Error.txt", "w", stderr);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    std::cout.unsetf(std::ios::floatfield); 
    std::cout << std::setprecision(10);
    lli t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}