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

Solution 1 (runtime: 93 ms):
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("Ofast") // also can use O3
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")
#ifndef LOCAL
#define debug(...) 1;
#else
#include "debug.h"
#endif
using namespace __gnu_pbds;
using namespace std;
using namespace chrono;
template<class T> using pq = priority_queue<T>;
template<class T> using pqr = priority_queue<T, vector<T>, greater<T>>;
#define int long long
#define pb push_back
#define fil(x, y) memset(x, y, sizeof(x))
#define ll long long
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define sz(x) (x).size()
#define pii pair<int,int>
#define pll pair<long long,long long>
#define inf 1073741823
#define infll 4611686018427387903
#define M 1000000007
#define db(x) cout << x << " ";
#define N 1007
#define sm 0.0000007
#define ins insert
#define ers erase
#define all(k) k.begin(), k.end()
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i, a, b) for (int i= a;i < b;i++)
#define Ford(i, a, b) for (int i = a;i >= b;i--)
/*
  a.order_of_key(x) -> index of x in a 
  *a.find_by_order(i) -> element at index i in a
*/
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


string a, b, c;
int dp[N][N];
int Dp(int i, int x)
{
    int j = x - i;
    if(x == c.size())
        return 0;
    if(dp[i][x] != -1)
        return dp[i][x];
    int ans = inf;
    if(i < a.size())
    {
        if(c[x] == a[i])
            ans = min(ans, Dp(i+1, x+1));
        else
            ans = min(ans, 1 + Dp(i+1, x+1));
    }
    if(j < b.size())
    {
        if(c[x] == b[j])
            ans = min(ans, Dp(i, x+1));
        else
            ans = min(ans, 1 + Dp(i, x+1));
    }
    return dp[i][x] = ans;
}
void solve(int testCase)
{
    cin >> a >> b >> c;
    for(int i = 0;i <= a.size();i++)
        for(int j = 0;j <= c.size();j++)
            dp[i][j] = -1;
    cout << Dp(0, 0) << "\n";
}

signed main()
{
    fastio;
    int _ = 1;
    cin >> _;
    for(int __=1; __<=_; __++)
    {
        solve(__);
    }
    return 0;
}


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

#ifdef Tx
#include "debug.h"
#else
#define dbg(...)
#endif
using ll = long long;

const int M = 1e3 + 7;
int dp[M][M];
string a, b, c;


int run (int p, int l, int r) {
  if (p == c.size()) return 0;
  int &ans = dp[l][r];
  if (ans != -1) return ans;
  ans = c.size();
  if (l < a.size()) ans = min(ans, run(p + 1, l+1 , r) + 1 - (c[p] == a[l]));
  if (r < b.size()) ans = min(ans, run(p + 1, l , r+1) + 1 - (c[p] == b[r]));
  return dp[l][r] = ans;
}

void solve () {
  memset(dp, -1, sizeof(dp));
  cin >> a >> b >> c;
  cout << run(0, 0, 0) << '\n';

}

int32_t main() {
  auto begin = std::chrono::high_resolution_clock::now();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in",  "r", stdin);
  // freopen("out", "w", stdout);  
  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;
}