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

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

#define int long long
#define INF (ll)1e18
#define f first
#define se second
#define pb push_back
#define all(v) v.begin(), v.end()
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define endl '\n'
#define ceil2(x, y) ((x + y - 1) / (y))

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

#ifndef ONLINE_JUDGE
// #include "debug.cpp"
#else
#define debug(...)
#define debugArr(...)
#endif

template <typename T>
void mini(T &a, T b) {
    a = min(a, b);
}

template <typename T>
void maxi(T &a, T b) {
    a = max(a, b);
}

const int N = 1e3 + 5;
const int MOD = 1e9 + 7;

// Global variables to handle DP and input strings
int dp[N][N]; // Adjusted size for possible maximum lengths
string a, b, c;
int n, m, l;

// Recursive function to find minimum operations
int rec(int i, int j, int idx) {
    if (idx == l) return 0; // If c is completely matched
    if (dp[i][j] != -1) return dp[i][j]; // Use memoized value

    int case1 = INT_MAX, case2 = INT_MAX;

    // Check case 1: Matching with string a
    if (i < n && a[i] == c[idx]) {
        case1 = rec(i + 1, j, idx + 1);
    } else if (i < n) {
        case1 = 1 + rec(i + 1, j, idx + 1);
    }

    // Check case 2: Matching with string b
    if (j < m && b[j] == c[idx]) {
        case2 = rec(i, j + 1, idx + 1);
    } else if (j < m) {
        case2 = 1 + rec(i, j + 1, idx + 1);
    }

    return dp[i][j] = min(case1, case2);
}

void Solve() {
    cin >> a >> b >> c;
    n = a.size();
    m = b.size();
    l = c.size();

    // Initialize DP array with -1
    memset(dp, -1, sizeof(dp));

    int ans = rec(0, 0, 0);
    cout << ans << endl;
}

int32_t main() {
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    cin >> t;

    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": ";
        Solve();
    }

    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    // cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
    return 0;
}

Solution 2 (runtime: 93 ms):

// author: arnavwinner

#include <bits/stdc++.h>
using namespace std;

const int INF = 1E9;
void print(vector<vector<int>> some) {
  for (auto x: some) {
    for (auto y: x) {
      cout << y << " ";
    }
    cout << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  int testno = 1;
  while (tt--) {
    string a, b, c;
    cin >> a >> b >> c;
    int n = a.size();
    int m = b.size();
    // cout << a << " " << b << " " << c << '\n';
    // cout << "tt: " << testno << '\n';
    // testno++;
    vector<vector<int>> dp(n + 1, vector<int> (m + 1, -1));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
      dp[i][0] = dp[i - 1][0] + (a[i - 1] != c[i - 1]);
      // print(dp);
      // cout << "\n--------------------\n";
    }
    for (int i = 1; i <= m; i++) {
      // cout << b[i - 1] << c[i - 1] << '\n';
      dp[0][i] = dp[0][i - 1] + (b[i - 1] != c[i - 1]);
      // print(dp);
      // cout << "\n--------------------\n";
    }
    function<int(int, int)> rec = [&] (int N, int M) -> int {
      // if (N < 0) return INF;
      // if (M < 0) return INF; // THIS DOESN'T WORK... You Initialized dp[N][M] with -1
      // now that you are checking only dp[N][M] != -1 below... that is v important to see
      if (dp[N][M] != -1) {
        return dp[N][M];
      }
      if (a[N - 1] == c[N + M - 1] && b[M - 1] != c[N + M - 1]) {
        return dp[N][M] = min(rec(N, M - 1) + 1, rec(N - 1, M));
      }
      if (a[N - 1] != c[N + M - 1] && b[M - 1] == c[N + M - 1]) {
        return dp[N][M] = min(rec(N, M - 1), rec(N - 1, M) + 1);
      }
      if (a[N - 1] == c[N + M - 1] && b[M - 1] == c[N + M - 1]) {
        return dp[N][M] = min(rec(N, M - 1), rec(N - 1, M));
      }
      if (a[N - 1] != c[N + M - 1] && b[M - 1] != c[N + M - 1]) {
        return dp[N][M] = min(rec(N, M - 1) + 1, rec(N - 1, M) + 1);
      }
    };
    cout << rec(n, m) << '\n';
    // cout << dp[n][m] << '\n';
    // for (int i = 0; i <= n; i++) {
    //   for (int j = 0; j <= m; j++) {
    //     cout << dp[i][j] << " ";
    //   }
    //   cout << '\n';
    // }
    // cout << "---------------\n";
  }
  return 0;
}