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

Solution 1 (runtime: 108 ms):
#include <iostream>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <fstream>
#include <utility>
#include <vector>
#include <set>
#include <queue>
#include <cassert>
#include <sstream>
#include <algorithm>
#include <array>
#include <cstring>

#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

const int maxn = 3 * (1<<10);
char A[maxn], B[maxn], C[maxn];
int DP[maxn][maxn];
int aN, bN, cN;


int go(int c, int a) {
    int& ans = DP[c][a];
    if (ans != -1) return ans;
    if (c == cN) {
        ans = 0;
        return ans;
    }
    ans = int(1e9);
    // c from a
    if (a < aN) {
        ans = min(ans, go(c + 1 , a + 1) + (C[c] == A[a] ? 0 : 1));
    }
    // c from b.
    int b = c - a;
    if (b < bN) {
        ans = min(ans, go(c + 1, a) + (C[c] == B[b] ? 0 : 1));
    }
    return ans;
}


int main() {
    int T;
    scanf("%d", &T);
    
    REP(t, T) {
        scanf("%s", A);
        scanf("%s", B);
        scanf("%s", C);
        aN = strlen(A), bN = strlen(B), cN = strlen(C);
        REP(i, cN+10) REP(j, aN+10) DP[i][j] = -1;
        int ans = go(0, 0);
        printf("%d\n", ans);
    }

}

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

#define ll long long

#define vi vector<ll>

#define vvi vector<vector<ll>>

#define vpi vector<pair<ll, ll>>

#define vc vector<char>

#define pb(a) push_back(a)

#define FOR(n, a)            \

  for (ll i = 0; i < n; i++) \

    cin >> a[i];

#define forn(i, n) for (ll i = 0; i < n; i++)

#define srt(vec) sort(vec.begin(), vec.end())

#define rsrt(vec) sort(vec.rbegin(), vec.rend())

#define as_second [](auto &x, auto &y) { return x.second < y.second; }

#define as_second_dec [](auto &x, auto &y) { return x.second > y.second; }

#define fast_io                     \

  ios_base::sync_with_stdio(false); \

  cin.tie(0);



using namespace std;

ll binexp(ll a, ll b, ll m)

{

  if (b == 0)

    return 1;

  ll res = binexp(a, b / 2, m);

  if (b % 2 != 0)

    return (((a % m) * (res % m)) % m * (res % m)) % m;

  return ((res % m) * (res % m)) % m;

}

bool get_bit(ll a, ll i)

{

  return a & (1ll << i);

}



bool isPowerOf2(ll n)

{

  return !(n & (n >> 1));

}



ll lcm(ll a, ll b)

{

  return a * b / __gcd(a, b);

}



void buildTree(ll idx, ll l, ll r, vi &segT, vi &a)

{

  if (l == r)

  {

    segT[idx] = a[l];

    return;

  }



  ll mid = l + (r - l) / 2;

  buildTree(2 * idx + 1, l, mid, segT, a);

  buildTree(2 * idx + 2, mid + 1, r, segT, a);



  segT[idx] = segT[2 * idx + 1] + segT[2 * idx + 2];

  return;

}



void update(ll i, ll s, ll e, ll val, ll l, ll r, vi &segT, vi &lazy)

{

  // cout << l << "," << r << " ";

  if (e < l || r < s || l > r)

    return;

  segT[i] += lazy[i] * (r - l + 1);

  if (l != r)

  {

    lazy[2 * i + 1] += lazy[i];

    lazy[2 * i + 2] += lazy[i];

  }

  lazy[i] = 0;

  if (s <= l && r <= e)

  {

    segT[i] += (r - l + 1) * val;

    if (l != r)

    {

      lazy[2 * i + 1] += val;

      lazy[2 * i + 2] += val;

    }

  }

  else

  {

    ll mid = l + (r - l) / 2;

    update(2 * i + 1, s, e, val, l, mid, segT, lazy);

    update(2 * i + 2, s, e, val, mid + 1, r, segT, lazy);

  }

}



ll find(vi &segT, vi &lazy, ll i, ll l, ll r, ll k)

{

  segT[i] += (r - l + 1) * lazy[i];

  if (l != r)

  {

    lazy[2 * i + 1] += lazy[i];

    lazy[2 * i + 2] += lazy[i];

  }

  lazy[i] = 0;

  if (l == r)

  {

    return segT[i];

  }



  ll mid = l + (r - l) / 2;

  if (k <= mid)

    return find(segT, lazy, 2 * i + 1, l, mid, k);



  return find(segT, lazy, 2 * i + 2, mid + 1, r, k);

}



ll solve(ll i, ll j, string &a, string &b, string &c, vvi &dp)

{

  ll n = a.length(), m = b.length();

  if (i >= n && j >= m)

    return 0;

  if (dp[i][j] != -1)

    return dp[i][j];



  ll case1 = 1e9, case2 = 1e9;

  if (i < n)

    case1 = solve(i + 1, j, a, b, c, dp) + (a[i] != c[i + j]);

  if (j < m)

    case2 = solve(i, j + 1, a, b, c, dp) + (b[j] != c[i + j]);



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

}



int main()

{

  fast_io;

  int t;

  cin >> t;

  while (t--)

  {

    string a, b, c;

    cin >> a >> b >> c;

    ll n = a.length(), m = b.length();

    vvi dp(n + 1, vi(m + 1, -1));

    ll ans = solve(0, 0, a, b, c, dp);

    cout << ans << endl;

  }

  return 0;

}