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

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;

//Speed
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Piyush cout.tie(NULL);

//Aliases
using ll = long long;
using lld = long double;
using ull = unsigned long long;

//Constants
const lld pi = 3.141592653589793238;
const ll INF = LONG_LONG_MAX;
const ll mod = 1000000007;

//TypeDEf
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;
typedef map<ll,ll> mll;
typedef vector<vector<ll>> vvll;

// Macros
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fl(i,n) for(int i=0;i<n;i++)
#define rl(i,m,n) for(int i=n;i>=m;i--)
#define vr(v) v.begin(),v.end()
#define rv(v) v.end(),v.begin()

// Mathematical functions
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
ll lcm(ll a, ll b){return (a/gcd(a,b)*b);}
ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)res = (res + a) % mod;b >>= 1;}return res;}
ll powermod(ll x, ll y, ll p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}

void print(vector<int> v){
    fl(i,v.size())cout<<v[i]<<" ";
    cout<<endl;
}

int foo(int p,int q,string a,string b,string c){
    if(p == 0 && q == 0){
        return 0;
    }
    int left = INT_MAX;
    int right = INT_MAX;
    if(p > 0){
        left = foo(p-1,q,a,b,c) + (c[p+q-1] != a[p-1]);
    }
    if(q > 0){
        right = foo(p,q-1,a,b,c) + (c[p+q-1] != b[q-1]);
    }

    return min(left,right);
}

void solve()
{
    string a,b,c;
    cin>>a>>b>>c;

    int n,m;
    n = a.size();
    m = b.size();

    cout<<foo(n,m,a,b,c)<<endl;;

}

//Main
int main()
{
    Code By Piyush;
    ll t;
    cin >> t;
    fl(i, t) {
        solve();
    }
    return 0;
}


Submission (verdict: Time limit exceeded on test 16):
#include <bits/stdc++.h>
using namespace std;

//Speed
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Piyush cout.tie(NULL);

//Aliases
using ll = long long;
using lld = long double;
using ull = unsigned long long;

//Constants
const lld pi = 3.141592653589793238;
const ll INF = LONG_LONG_MAX;
const ll mod = 1000000007;

//TypeDEf
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;
typedef map<ll,ll> mll;
typedef vector<vector<ll>> vvll;

// Macros
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fl(i,n) for(int i=0;i<n;i++)
#define rl(i,m,n) for(int i=n;i>=m;i--)
#define vr(v) v.begin(),v.end()
#define rv(v) v.end(),v.begin()

// Mathematical functions
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
ll lcm(ll a, ll b){return (a/gcd(a,b)*b);}
ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)res = (res + a) % mod;b >>= 1;}return res;}
ll powermod(ll x, ll y, ll p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}

void print(vector<int> v){
    fl(i,v.size())cout<<v[i]<<" ";
    cout<<endl;
}

int foo(int p,int q,string a,string b,string c,vector<vector<int>> &dp){
    if(p == 0 && q == 0){
        return 0;
    }
    if(dp[p][q] != -1){
        return dp[p][q];
    }
    int left = INT_MAX;
    int right = INT_MAX;
    if(p > 0){
        left = foo(p-1,q,a,b,c,dp) + (c[p+q-1] != a[p-1]);
    }
    if(q > 0){
        right = foo(p,q-1,a,b,c,dp) + (c[p+q-1] != b[q-1]);
    }

    return dp[p][q] = min(left,right);
}

void solve()
{
    string a,b,c;
    cin>>a>>b>>c;
    int n,m;
    n = a.size();
    m = b.size();
    vector<vector<int>> dp(n+1,vector<int> (m+1,-1));

    cout<<foo(n,m,a,b,c,dp)<<endl;

}

//Main
int main()
{
    Code By Piyush;
    ll t;
    cin >> t;
    fl(i, t) {
        solve();
    }
    return 0;
}