Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 16):
#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 endl "\n"
#define int long long
#define pb push_back
#define cy cout <<"YES"<< endl
#define cn cout <<"NO"<< endl
#define all(x) x.begin(),x.end()
#define fastread std::ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int MOD = 1e18+7;
int ceil_div(int a, int b) { return a%b==0 ? a/b : a/b+1;}
int gcd(int a, int b) { if(a==0LL) { return b;} return gcd(b%a, a);}
int lcm(int a, int b) {return a*b/gcd(a,b);}

bool sorted(pair<int,int> &a, pair<int,int> &b) {
    if(a.first == b.first) 
        return a.second < b.second; // ascending
    return a.first > b.first; // descending
}

int exp(int a, int b) {
    if(b==0) return 1;
    int half_power = exp(a,b/2);
    a %= MOD;
    if(b%2==0) return half_power * half_power % MOD;
    else return half_power * half_power % MOD * (a%MOD) % MOD;
}

void SieveOfEratosthenes(int n) {
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
    for (int p = 2; p * p <= n; p++) {
        if (prime[p] == true) {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
}

int isPrime(int n) {
    for(int i=2; i*i<=n; i++) {
        if(n%i ==0)
            return false;
    }
    return true;
}

int fn(string a, string b, int i) {
    int count = 0;
    for(int j=i; j>=0; j--) {
        if(a[j] != b[j])
            count++;
    }
    return count;
}

int cf(string a, string b, string c, int n, int m, int i, vector<vector<int>> &dp) {
    if(i < 0)
        return 0;
    if(n < 0)
        return fn(b,c,m);
    if(m < 0)
        return fn(a,c,n);
    if(dp[n][m] != -1)
        return dp[n][m];
    int res = 1e9;
    if(a[n] == c[i] && b[m] == c[i])
        res = min(cf(a,b,c,n-1,m,i-1,dp), cf(a,b,c,n,m-1,i-1,dp));
    else if(a[n] == c[i])
        res = min(cf(a,b,c,n-1,m,i-1,dp), 1+cf(a,b,c,n,m-1,i-1,dp));
    else if(b[m] == c[i])
        res = min(cf(a,b,c,n,m-1,i-1,dp), 1+cf(a,b,c,n-1,m,i-1,dp));
    else 
        res = min(1+cf(a,b,c,n-1,m,i-1,dp), 1+cf(a,b,c,n,m-1,i-1,dp));
    return dp[n][m] = res;
}

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

signed main() {
    fastread
    int t = 1; cin >> t;
    while(t--) {
        solve();
    }
}

Submission (verdict: Time limit exceeded on test 16):
#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 endl "\n"
#define int long long
#define pb push_back
#define cy cout <<"YES"<< endl
#define cn cout <<"NO"<< endl
#define all(x) x.begin(),x.end()
#define fastread std::ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int MOD = 1e18+7;
int ceil_div(int a, int b) { return a%b==0 ? a/b : a/b+1;}
int gcd(int a, int b) { if(a==0LL) { return b;} return gcd(b%a, a);}
int lcm(int a, int b) {return a*b/gcd(a,b);}

bool sorted(pair<int,int> &a, pair<int,int> &b) {
    if(a.first == b.first) 
        return a.second < b.second; // ascending
    return a.first > b.first; // descending
}

int exp(int a, int b) {
    if(b==0) return 1;
    int half_power = exp(a,b/2);
    a %= MOD;
    if(b%2==0) return half_power * half_power % MOD;
    else return half_power * half_power % MOD * (a%MOD) % MOD;
}

void SieveOfEratosthenes(int n) {
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
    for (int p = 2; p * p <= n; p++) {
        if (prime[p] == true) {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
}

int isPrime(int n) {
    for(int i=2; i*i<=n; i++) {
        if(n%i ==0)
            return false;
    }
    return true;
}

int fn(string a, string b, int i) {
    int count = 0;
    for(int j=i; j>=0; j--) {
        if(a[j] != b[j])
            count++;
    }
    return count;
}

int cf(string a, string b, string c, int i, int j, vector<vector<int>> &dp) {
    if(i==a.size() && j==b.size())
        return 0;
    if(dp[i][j] != -1)
        return dp[i][j];
    int pos = i+j, res = 1e9;
    if(i < a.size()) {
        int cos = cf(a,b,c,i+1,j,dp) + (a[i] != c[pos]);
        res = min(res, cos);
    }
    if(j < b.size()) {
        int cos = cf(a,b,c,i,j+1,dp) + (b[j] != c[pos]);
        res = min(res, cos);
    }
    return dp[i][j] = res;
}

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

signed main() {
    fastread
    int t = 1; cin >> t;
    while(t--) {
        solve();
    }
}