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

Solution 1 (runtime: 77 ms):
// Sebastian Galindo

 
#include <bits/stdc++.h>
#include <regex>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
 
#define forn(i, a) for (int i=0; i<(a); i++)
#define fornm(i, m, n, x) for (int i = (m); i < (n); i += (x))
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
 
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x);
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define debug(x...)
#endif
 

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; 

void solve() {
    string a, b, c; cin >> a >> b >> c;
    a += '#'; b+= '#';
    vector<vi> memo(len(a)+5, vi(len(b)+5, -1));
    auto dp = [&](auto &&dp, int i, int j) -> int {
        if (i == len(a) || j == len(b)) return len(c);
        if (i == len(a)-1 && j == len(b)-1) return 0;
        if (memo[i][j] != -1) return memo[i][j];
        int f = len(c), s = len(c);
        ckmin(f, (a[i] != c[i+j]) + dp(dp, i+1, j));
        ckmin(s, (b[j] != c[i+j]) + dp(dp, i, j+1));
        //debug(min(f, s), i, j);
        return memo[i][j] = min(f, s);
    };

    cout << dp(dp, 0, 0) << nl;
}
 
int main() {
    cin.tie(0)->sync_with_stdio(0); 
    cin.exceptions(cin.failbit);
 
    int T = 1;
    cin >> T;
    while(T--) {
    solve();
    }
 
	return 0;
}
 



Solution 2 (runtime: 2390 ms):
#define _GLIBCXX_FILESYSTEM
#include <bits/stdc++.h>
using namespace std ;
#define int long long
const int N = 2e5+5 ;
const int M = 1e6+5 ;
const int INF = 1e18  ;
 int mod = 1e9 + 7 ;
const double pi = acos(-1.0) ;

int T = 1 ;







// void bfs(int ver){
//     level[ver] = 0 ;
//     queue < int > q ;
//     q.push(1) ;
//     while(!q.empty()){
//         int fnt = q.front() ;
//         q.pop() ;
//         for(auto it : v[fnt]){

//             if(it == 1){
//                 mn =  min(mn , level[fnt]+1) ;
//                 continue ;
//             }
//             if(level[it] == -1){
//                 //cout << fnt << " " << it << endl ;
//                 level[it] = level[fnt] + 1 ;
//                 q.push(it) ;
//             }
//         }
//     }
// }








// int big_mod(int key, int pow)
// {
//     int ans = 1 ;
//     if(pow == 0) return 1 ;
//     ans = big_mod(key,pow/2) ;
//     ans = 1LL * ans * ans % mod ;
//     if(pow&1) ans = 1LL * ans * key % mod;
//     return ans ;
// }
 



int poww(int n){
    int x = 1 ;
    for(int i = 0 ; i < n ; i++){
        x *= 2 ;
        x %= mod ;
    }
    return x ;
}       


// string dtob(int n){
//     string x ;
//     while(n > 0){
//         if(n%2 == 0) x.push_back('0') ;
//         else x.push_back('1') ;
//         n /= 2 ;
//     }
//     //cout << x << endl ;
//     return x ;
// }


// int dfs(int x){
//         if(level[x] != -1) return level[x] ; 
//        int mx= 0 ;
//        for(auto it : v[x]){
//             mx = max(mx , 1 + dfs(it)) ;
//        }
//        level[x] = mx ;
//        return mx ;
// }


// void dfs(int ver){
//   vis[ver] = 1 ;
//   for(auto it : v[ver]){
//       if(vis[it] == 1) continue ;
//       if(v[it].size() == 3){
//           if(mp[it] > 0) cnt += mp[it] ;
//           dfs(it) ;
//       }
//   }

// }






   
// int spf[N] ;
 
// void sieve(){
//     spf[1] = 1 ;
//     for(int i = 2 ; i < N ; i++){
//         spf[i] = i ;
//         if(i%2 == 0) spf[i] = 2 ;
//     }
//     for(int i = 3 ; i*i < N ; i++){
//         if(spf[i] == i){
//             for(int j = i*i ; j < N ; j +=i){
//                 if(spf[j] == j) spf[j] = i ;
//             }
//         }
//     }
// }


string a , b , c ;
int n , m , l ;
int dp[2002][1002] ;

int fun(int ind1 , int ind2 ){
        if(ind1 == l){
            return 0 ;
        }
        if(dp[ind1][ind2] != -1) return dp[ind1][ind2]  ;

        int from_a = INT_MAX ;
        int from_b = INT_MAX ;

        if(ind2 < n){
            from_a = fun(ind1+1 , ind2+1) ;
            if(c[ind1] != a[ind2]) from_a++ ;

        }

        int ind3 = ind1 - ind2 ;

        if(ind3 < m){
            from_b = fun(ind1+1 , ind2) ;
            if(c[ind1] != b[ind3]) from_b++ ;

        }

        return dp[ind1][ind2] = min(from_a , from_b) ;

        

}






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

    for(int i = 0; i < 2002 ; i++){
        for(int j = 0 ; j < 1002 ; j++){
            dp[i][j] = -1 ;
        }
    }

    int ans = fun(0 , 0 ) ;
    cout << ans << endl ;
    


}






int32_t main()
{

    ios_base :: sync_with_stdio(false) ; cin.tie(NULL) ; cout.tie(NULL) ;
    //pre() ;
    int t= 1 ;
    cin >> t ;
    while(t--){
        //cout << "Case "<< T++ << ": " ;
        solve() ;
        //cout << t<< "t" << endl;
    }


}