Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 124 ms):

/**
 *    author:  vishal
 *    created: 08.12.2024 11:52
**/

#include <bits/stdc++.h>
using namespace std;
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max(a,b),max(d,c))
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(min(a,b),min(d,c))
#define MIN(arr, n) (*min_element(arr, arr + n))
#define MAX(arr, n) (*max_element(arr, arr + n))

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a * (b / gcd(a,b)))

#define set_cnt(n) __builtin_popcount(n)
#define set_bit(x, i) ((x) | (1LL << (i))) //ith bit of x to 1
#define clear_bit(x, i) ((x) & ~(1LL << (i))) //unset
#define toggle(x, i) ((x) ^ (1LL << (i)))
#define is_set(x, i) ((x) & (1LL << (i)))
#define is_pow2(x) ((x) && !((x) & ((x) - 1)))

#define in(arr,n) for(int i=0; i<n; i++){cin>>arr[i];}
#define out(arr,n) for(int i=0; i<n; i++){cout<<arr[i]<<" ";}
#define matout(a,b,arr){for(int i=0; i<a; i++){for(int j=0; j<b; j++){cout<<arr[i][j]<<" ";}cout<<endl;}}
#define sum(arr, n) accumulate(arr, arr + n, 0LL)

#define loop(n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rep2(i, j, a, b, c, d) for(int i = a; i < b; i++) for(int j = c; j < d; j++)
#define debug(x) cerr << "Debug: " << #x << " = " << (x) << endl;
#define ll long long
#define hello(x) cerr<<"hello"<<(x)<<endl;
#define MOD ((int)(1e9 + 7))
#define print(arr,n) rep(i,0,n){cout<<arr[i]<<" ";}

/*
int fun(string s1,string s2,string s,int i,int j,int k,vector<vector<int>> &dp){
    //base case
    int n1 = s1.length(),n2=s2.length(),n=s.length();
    // if(i == 0){
    //     if(s[k] == s1[i]) return 0;
    //     else return 1;
    // }
    // if(j == 0){
    //     if(s[k] == s2[j]) return 0;
    //     else return 1;
    // }
    //cout<<i<<" "<<j<<" "<<k<<endl;
    //if(i<0 || j<0) return 1;
    if(i == 0 && s[k] == s1[i]) return 0;
    if(i == 0) return 1;
    if(j == 0 && s[k] == s2[j]) return 0;
    if(j == 0) return 1;
    
    // if(k == 0){
    //     if(i == 0 && s[k] == s1[i]) return 0;
    //     if(j == 0 && s[k] == s2[j]) return 0;
    //     return 1;
    // }
    //if(i<0 || j<0) return 1e9;
    if(dp[i][j] != -1) return dp[i][j];
    int ans = 1e9;
    if(i>=0 && j>=0 && s1[i] == s[k] && s2[j] == s[k]){
        ans = 0 + min(fun(s1,s2,s,i-1,j,k-1,dp),fun(s1,s2,s,i,j-1,k-1,dp));
    }
    else if(i>=0 && s1[i] == s[k]){
        ans = fun(s1,s2,s,i-1,j,k-1,dp);
    }else if(j>=0 && s2[j] == s[k]){
        ans = fun(s1,s2,s,i,j-1,k-1,dp);
    }else{
        int a1=1e9,a2=1e9;
        if(i>=1)
            a1 = 1+fun(s1,s2,s,i-1,j,k-1,dp);
        if(j>=1)
            a2 = 1+fun(s1,s2,s,i,j-1,k-1,dp);
        ans = min(a1,a2);
    }
    return dp[i][j]=ans;
}*/
int fun(string &s1, string &s2, string &s, int i, int j, int k, vector<vector<int>> &dp) {
    if (k < 0) return (i < 0 && j < 0) ? 0 : 1e9;
    if (i < 0 && j < 0) return 1e9;
    if (dp[i+1][j+1] != -1) return dp[i+1][j+1];

    int ans = 1e9;

    if (i >= 0 && s1[i] == s[k]) 
        ans = min(ans, fun(s1, s2, s, i-1, j, k-1, dp));
    if (j >= 0 && s2[j] == s[k]) 
        ans = min(ans, fun(s1, s2, s, i, j-1, k-1, dp));
    if (i >= 0) 
        ans = min(ans, 1 + fun(s1, s2, s, i-1, j, k-1, dp));
    if (j >= 0) 
        ans = min(ans, 1 + fun(s1, s2, s, i, j-1, k-1, dp));

    return dp[i+1][j+1] = ans;
}

void solve() {
    string s1, s2, s;
    cin >> s1 >> s2 >> s;
    int i = s1.length() - 1, j = s2.length() - 1, k = s.length() - 1;
    vector<vector<int>> dp(i+2, vector<int>(j+2, -1)); 
    int ans = fun(s1, s2, s, i, j, k, dp);
    cout << ans << endl;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define float double

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define inp(x) \
    int x;     \
    cin >> x;

#define pb push_back
#define fr(i, b) for (int i = 0; i < (int)(b); i++)
#define scanarr                 \
    int a[n];                   \
    for (int i = 0; i < n; i++) \
    cin >> a[i]
#define sz(a) (int)(a.size())
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define lower(a, b) lower_bound((a).begin(), (a).end(), (int)(b))
#define upper(a, b) upper_bound((a).begin(), (a).end(), (int)(b))
#define lower_ind(a, b) lower_bound((a).begin(), (a).end(), (int)(b)) - (a).begin()
#define upper_ind(a, b) upper_bound((a).begin(), (a).end(), (int)(b)) - (a).begin()

typedef vector<int> vi;
typedef set<int> si;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

void solve()
{
    string a;
    string b;
    string c;
    cin >> a >> b >> c;
    int n = a.size();
    int m = b.size();
    vector dp(n + 1, vector(m + 1, 1e9));
    dp[0][0] = 0;
    for (int i = 1; i <= m; i++)
    {
        if (b[i - 1] != c[i - 1])
        {
            dp[0][i] = dp[0][i - 1] + 1;
        }
        else
        {
            dp[0][i] = dp[0][i - 1];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = dp[i - 1][0];
        if (a[i - 1] != c[i - 1])
        {
            dp[i][0] += 1;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (a[i - 1] == c[i + j - 1] && b[j - 1] == c[i + j - 1])
            {
                dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);
            }
            else if (a[i - 1] == c[i + j - 1])
            {
                dp[i][j] = min(dp[i - 1][j], dp[i][j - 1] + 1);
            }
            else if (b[j - 1] == c[i + j - 1])
            {
                dp[i][j] = min(dp[i][j - 1], dp[i - 1][j] + 1);
            }
            else if (a[i - 1] != c[i + j - 1] && b[j - 1] != c[i + j - 1])
            {
                dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1;
            }
        }
    }
    cout << dp[n][m] << endl;
}

signed main()
{
    fast;
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}