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

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

const int MAX_N = (int) 1e3;
const int INF = (int) 1e9;
int dp[MAX_N + 1][MAX_N + 1];
string a, b, c;
int n, m;

int sol (int i = 0, int j = 0) {
    if (i == n and j == m) {
        return 0;
    }
    int& ans = dp[i][j];
    if (ans != -1) {
        return ans;
    }
    ans = INF;
    int k = i + j;
    if (i < n) {
        ans = min(ans, sol(i + 1, j) + (a[i] != c[k]));
    }
    if (j < m) {
        ans = min(ans, sol(i, j + 1) + (b[j] != c[k]));
    }
    return ans;
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    while (tt--) {
        cin >> a >> b >> c;
        n = (int) a.size();
        m = (int) b.size();
        for (int i = 0; i <= n; ++i) {
            for (int j = 0; j <= m; ++j) {
                dp[i][j] = -1;
            }
        }   
        cout << sol() << '\n';
    }
    return 0;
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>

#include <iostream>

#include <set>

#include <vector>

#include <map>

#include <unordered_map>

#include <algorithm>

#include <queue>

#include <numeric>

#include <iomanip>

#include <unordered_set>

using namespace std;

using ll = long long;

// using ld = long double;

ll n,m,k,t;

const int mxn = 5e3;

const ll inf = LLONG_MAX;

const ll infMin = LLONG_MIN;



void fileIO(string filename) {

	freopen((filename + ".in").c_str(), "r", stdin);

	freopen((filename + ".out").c_str(), "w", stdout);

}















void solve() {

    string a, b, c;

    cin >> a >> b >> c;

    if (b.size() > a.size()) {

        swap(a, b);

    }

    vector<ll>dp(2002, 0);

    for (ll i = 0; i < c.size(); i++) {

        char lastC = c[i];



        vector<ll>dp2(2002, 0);

        for (ll cntA = 0; cntA <= i + 1; cntA++) {

            ll cntB = i + 1 - cntA;

            if (cntA <= a.size() and cntB <= b.size()) {

                if (dp[cntA] != -1)

                    dp2[cntA] = dp[cntA];

                if (cntA >= 1 and dp[cntA - 1] != -1) {

                    dp2[cntA] = max(dp2[cntA], dp[cntA - 1]);

                }

                char lastA;

                char lastB;

                if (cntA == 0) {

                    lastA = '0';

                } else {

                    lastA = a[cntA-1];

                }



                if (cntB == 0) {

                    lastB = '0';

                } else {

                    lastB = b[cntB-1];

                }



                if (lastA == lastC and dp[cntA - 1] != -1) {

                    

                    dp2[cntA] = max(dp2[cntA], dp[cntA - 1] + 1);

                }

                if (lastC == lastB and dp[cntA] != -1) {

                    dp2[cntA] = max(dp2[cntA], dp[cntA] + 1);

                }

            } else {

                dp2[cntA] = -1;

            }

            // cout << " c size " << i + 1 << " " << cntA << " " << cntB << " dp2 " << dp2[cntA] << " " << endl;

        }

        dp = dp2;

    }



    

    cout << c.size() - dp[a.size()] << "\n";



}





int main ()

{	

    ios_base::sync_with_stdio( 0 );

    cin.tie( 0 );

    cin >> t;

    // t = 1;

    while (t--) {

	    solve();

    }

}