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

Solution 1 (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;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order to find the Kth element (0 base indexing) and it returns iterator
// order_of_key to find number of elements smaller than x
// to erase from pbds (_equal) use order_of_key and than by its index find its iterator using find_by_order than erase it 
//upper and lower bound works same as set 

#define int long long
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define sqrt(x) sqrtl(x)
#define MOD 1000000007
#define MOD1 998244353
#define PI 3.141592653589793238462
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define vi vector<int>
#define vvi vector<vector<int>>
#define endl "\n"
#define pii pair<int,int>
#define f(i,a,b) for(int i=a;i<b;i++)
#define in(a,n) for(int i = 0; i<n; i++) cin>>a[i]
#define out(a,n) for(int i = 0; i<n; i++) cout<<a[i]<<" "
#define debug(x) cout<<#x<<"-->"<<x<<endl
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//--------------------ncr
int ncr(int n,int r){
    if(r>n/2) r=n-r;
    int res=1;
    for(int i=0;i<r;i++){res*=(n-i);res/=(i+1);}
    return res;
}
//-----------------------BINARY SEARCH
int binsearch(int a[],int val, int n){
    int lo=0;
    int hi=n-1;
    while(hi-lo>1){
        int mid=(lo+hi)/2;
        if(val>a[mid]){
            lo=mid+1;
        }
        else{
            hi=mid;
        }
    }
    if(a[lo]==val){
        return lo;
    }else if(a[hi]==val){
        return hi;
    }
    else{
        return -1;
    }
}
//--------MODULAR EXPONENTATION
int modexp(int a,int b,int m){
    int result=1;
    while(b>0){
    if(b&1){
   result=(result*1ll*a)%m;
    }
    a=(a*1ll*a)%m;
    b>>=1;
   }
    return result;
}
//---------------POWER FUNCTION
int binExpRec(int a, int b){
if (b == 0){
return 1;}
int res = binExpRec(a, b / 2);
if (b & 1){
return a * res * res;}
else{
return  res * res;
}}
int ans(string &a,string &b,string &c,int n,int m, vector<vector<int>>&dp,int i,int j){
    if(i==n){
        int ct=0;
        for(int k=j;k<m;k++){
            if(b[k]!=c[i+k]) ct++;
        }
        return ct;
    }
     if(j==m){
        int ct=0;
        for(int k=i;k<n;k++){
            if(a[k]!=c[j+k]) ct++;
        }
        return ct;
    }
    if(dp[i][j]!=-1) return dp[i][j];
    int anss=INT_MAX;
    if(a[i]==c[i+j]){
        anss=min(anss,ans(a,b,c,n,m,dp,i+1,j));
    }
    if(b[j]==c[i+j]){
        anss=min(anss,ans(a,b,c,n,m,dp,i,j+1));
    }
    if(a[i]!=c[i+j] || b[j]!=c[i+j]){
        anss=min(anss,1ll+min(ans(a,b,c,n,m,dp,i+1,j),ans(a,b,c,n,m,dp,i,j+1)));
    }
    return anss;
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n=a.size();
    int m=b.size();
    vector<vector<int>>dp(n+1,vector<int>(m+1,0));
    // cout<<ans(a,b,c,n,m,dp,0,0)<<endl;
    int ct=0;
    for(int i=m-1;i>=0;i--){
        if(b[i]!=c[n+i]) ct++;
        dp[n][i]=ct;
    }
    ct=0;
    for(int i=n-1;i>=0;i--){
        if(a[i]!=c[m+i]) ct++;
        dp[i][m]=ct;
    }
    for(int i=n-1;i>=0;i--){
        for(int j=m-1;j>=0;j--){
            int anss=INT_MAX;
    if(a[i]==c[i+j]){
        anss=min(anss,dp[i+1][j]);
    }
    if(b[j]==c[i+j]){
        anss=min(anss,dp[i][j+1]);
    }
    if(a[i]!=c[i+j] || b[j]!=c[i+j]){
        anss=min(anss,1ll+min(dp[i+1][j],dp[i][j+1]));
    }
    dp[i][j]=anss;
        }
    }
    cout<< dp[0][0]<<endl;
}
//vector<bool> isprime(MOD,1);
signed main (){
fastio
//isprime[0]=isprime[1]=false;
//for(int i=2;i*i<MOD;++i){
//if(isprime[i]){
//for(int j=i*i;j<MOD;j+=i){
// isprime[j]=false;
// }
// }
// }
int T;
cin>>T;
while(T--){
solve();
}
    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        string a, b, c;
        cin >> a >> b >> c;
        int n = a.size();
        int m = b.size();
        // Check length
        if(n + m != (int)c.size()){
            // According to problem statement, this should not happen
            cout << "-1\n";
            continue;
        }
        // Initialize dp and dp_new
        vector<int> dp(m+1, 0);
        // Initialize dp[0][j]
        for(int j=1; j<=m; j++){
            dp[j] = dp[j-1] + (b[j-1] != c[j-1] ? 1 : 0);
        }
        // Temporary vector for dp_new
        vector<int> dp_new(m+1, 0);
        // Iterate over a
        for(int i=1; i<=n; i++){
            // j =0
            dp_new[0] = dp[0] + (a[i-1] != c[i-1] ? 1 : 0);
            for(int j=1; j<=m; j++){
                // Take from a
                int take_a = dp[j] + ((a[i-1] != c[i+j-1]) ? 1 : 0);
                // Take from b
                int take_b = dp_new[j-1] + ((b[j-1] != c[i+j-1]) ? 1 : 0);
                dp_new[j] = min(take_a, take_b);
            }
            // Swap dp and dp_new
            dp.swap(dp_new);
        }
        // The answer is dp[m]
        cout << dp[m] << "\n";
    }
}