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

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<long long,long long>> vpll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unordered_map<int,int> umpii;
typedef map<int,int> mpii;

ll MOD = 1e9 + 7;
ll MOD_1 = 998244353;

# define print(x) for(auto & it : x)cout<<it<<' '; cout<<endl;
# define print_d(x) for(auto & it : x)cout<<it.first<<' '<<it.second<<endl;
# define print_pq(x) while(!x.empty()){cout<<x.top()<<" "; pq.pop();} cout<<endl;
# define print_q(x) while(!x.empty()){cout<<x.front()<<" "; pq.pop();} cout<<endl;
# define all(x) x.begin(),x.end()

/* NUMBER THEORY */
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}

/* nCr function */
// not included right now 

ll mm_inv_prime(ll a, ll m) {return expo(a, m - 2, m);}

ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mm_inv_prime(b, m), m) + m) % m;}  //only for prime m

int gcdExtended(int a, int b, int &x, int &y) {
    if (a == 0) {
        x = 0, y = 1;
        return b;
    }
    int x1, y1;
    int gcd = gcdExtended(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return gcd;
}

int crt(vector<int> num, vector<int> rem) {
    int prod = 1;
    for (int n : num) prod *= n;

    int result = 0;
    for (int i = 0; i < num.size(); i++) {
        int pp = prod / num[i];
        int x, y;
        gcdExtended(pp, num[i], x, y);
        result += rem[i] * pp * x;
    }
    return (result % prod + prod) % prod;
}

/*                ARRAY INP               */
template<typename T>
void inp_array(T array_name[],size_t size_of_array)
{
    for (size_t i = 0; i < size_of_array; i++)
    {
        cin>>array_name[i];
    }
}
 
/*                VECTOR INP                */
template<typename T>
void inp_array(vector<T> &array_name,size_t size_of_array)
{
    for (size_t i = 0; i < size_of_array; i++)
    {
        cin>>array_name[i];
    }
}

/*         Number of Digits         */
template<typename T>
int no_dig(T n){
    int cnt = 0;
    while (n>0)
    {
        cnt++;
        n /=10;
    }
    return cnt;
}

/*          Count Unique          */
template<typename T>
vector<int> convertToCountArray(vector<T> &arr, int n) {
    vector<int> countArray;

    int count = 1; // Start counting from the first element
    for (int i = 1; i < n; ++i) {
        if (arr[i] == arr[i - 1]) {
            ++count; // Increment the count if the current element is the same as the previous one
        } else {
            countArray.push_back(count); // Push the count and reset for the next sequence
            count = 1;
        }
    }
    countArray.push_back(count); // Push the last count

    return countArray;
}

/*     Your Functions     */
int solve(string &a, string &b, string &c, vector<vi> &dp, int n, int m, int i, int j, int cnt){
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = dp[i-1][0] + (a[i-1]!=c[i-1]);
    }
    for (int j = 1; j <= m; j++)
    {
        dp[0][j] = dp[0][j-1] + (b[j-1]!=c[j-1]);
    }
    

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            dp[i][j] = min(
                dp[i-1][j] + (a[i-1]!=c[i+j-1]),
                dp[i][j-1] + (b[j-1]!=c[i+j-1])
            );
        }
        
    }
    
    return dp[n][m];
    // if (i==n && j==m)
    // {
    //     res = min(res,cnt);
    // }

    // if(i<n)
    //     solve(a,b,c,dp,n,m,i+1,j,cnt+(a[i]!=c[i+j]),res);
    // if(j<m)
    //     solve(a,b,c,dp,n,m,i,j+1,cnt+(b[j]!=c[i+j]),res);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        
    int t=1;
    cin>>t;
    
    while(t--)
    {
        string a,b,c;
        cin>>a>>b>>c;

        int n = a.length();
        int m = b.length();

        int res = n + m;
        vector<vi> dp(n+1,vi(m+1,0));
        
        cout<<solve(a,b,c,dp,n,m,0,0,0);;
        cout<<"\n";
    }
    return 0;
}

Solution 2 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e5+5
vector<vector<int>> dp;
int solve(string a,string b,string c,int ind1,int ind2){
    // base case
    // cout<<ind1<<" "<<ind2<<endl;
    if(ind1 == a.size() && ind2 == b.size()){
        return 0;
    }
    if(dp[ind1][ind2] != -1){
        return dp[ind1][ind2];
    }
    int op1 = inf;
    int op2 = inf;
    int op3 = inf;
    int op4 = inf;

    if(a[ind1] == c[ind1+ind2] && ind1<a.size()){
        op1 = solve(a,b,c,ind1+1,ind2);
    }
    if(b[ind2] == c[ind1+ind2] && ind2<b.size()){
        op2 = solve(a,b,c,ind1,ind2+1);
    }
    if(ind1<a.size())op3 = 1 + solve(a,b,c,ind1+1,ind2);
    if(ind2<b.size())op4 = 1 + solve(a,b,c,ind1,ind2+1);
    return dp[ind1][ind2] = min({op1,op2,op3,op4});
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        int k = c.size();
        dp = vector<vector<int>>(n+1,vector<int>(m+1,-1));
        dp[n][m] = 0;
        // int ans = solve(a,b,c,0,0); 
        for(int i=(n);i>=0;i--){
            for(int j=(m);j>=0;j--){
                if(i==n && j==m) continue;
                int op1 = inf;
                int op2 = inf;
                int op3 = inf;
                int op4 = inf;
                if(i<n && a[i] == c[i+j]){
                    op1 = dp[i+1][j];
                }
                if(j<m && b[j] == c[i+j]){
                    op2 = dp[i][j+1];
                }
                if(i<n)op3 = 1 + dp[i+1][j];
                if(j<m)op4 = 1 + dp[i][j+1];
                dp[i][j] = min(op1,min(op2,min(op3,op4)));
            }
        }
        cout<<dp[0][0]<<endl;
        // cout<<ans<<endl;
    }
}