Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 2):
/* Vivek Dhir */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long int li;
typedef long long int ll;
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define FA(i, start, end) for (int i = start; i < end; i++)
#define setbits(x) __builtin_popcountll(x)// counts no. of 1s
#define zrobits(x) __builtin_ctzll(x)// counts no. of zeros on left
#define mod 1000000007
#define INF 322337200489576
#define VI vector<int>
#define VL vector<ll>
#define AI(arr, t) VL arr(t); FA(i, 0, t) cin>>arr[i];
#define print(arr) for(auto x: arr) cout<< x <<' '; cout<<'\n';
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second
#define MP make_pair
#define WINNING() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#ifndef ONLINE_JUDGE
#define debug(x) cerr << x<< endl;
#endif
ll expo(ll a, ll b, ll M) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % M; a = (a * a) % M; b = b >> 1;} return res;}
void fil(){ 
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);freopen("error.txt", "w", stderr); 
#endif
}
/*-------------------------------------------------------------------------------------------------------------------------------------*/

int ans(vector<vector<int> > &dp,string &a, string &b, string &c, int i, int j, int k){
    if(c.length()==k){
        return 0;
    }
    if(dp[i][j]!=-1) return dp[i][j];
    int fans = INT_MAX;
    if(i==a.length()){
        if(b[j]==c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i+1, j, k+1)+1, ans(dp, a, b, c, i, j+1, k+1)));
        }
        else{
            fans = min(fans, ans(dp, a, b, c, i, j+1, k+1)+1);
        }
    }if(j==b.length()){
        if(a[i]==c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i+1, j, k+1), ans(dp, a, b, c, i, j+1, k+1)+1));
        }
        else{
            fans = min(fans, ans(dp, a, b, c, i+1, j, k+1)+1);
        }
    }
    if(j!=b.length() && i!=a.length()){
        if(a[i]==c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i+1, j, k+1), ans(dp, a, b, c, i, j+1, k+1)+1));
        }
        if(b[j]==c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i+1, j, k+1)+1, ans(dp, a, b, c, i, j+1, k+1)));
        }
        if(b[j]!=c[k] && a[i]!=c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i, j+1, k+1)+1,  ans(dp, a, b, c, i+1, j, k+1)+1));
        }
    }
    return dp[i][j] = fans;
}

void solve(){
    string a, b, c;
    cin>>a>>b>>c;
    // cout<< a<<" "<<b<<" "<<c<<" ";
    vector<vector<int> > dp(a.length()+1, vector<int>(b.length()+1, -1));
    cout<<ans(dp, a, b, c, 0, 0, 0)<<"\n";
}

int main(){
    WINNING(); fil(); 
    ll t = 1;
    cin>>t;
    FA(i, 1, t+1){
        // cout << "Case #"<< i <<": ";
        solve(); 
        //cout<<"\n";
    }
}

Submission (verdict: Accepted):
/* Vivek Dhir */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long int li;
typedef long long int ll;
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define FA(i, start, end) for (int i = start; i < end; i++)
#define setbits(x) __builtin_popcountll(x)// counts no. of 1s
#define zrobits(x) __builtin_ctzll(x)// counts no. of zeros on left
#define mod 1000000007
#define INF 322337200489576
#define VI vector<int>
#define VL vector<ll>
#define AI(arr, t) VL arr(t); FA(i, 0, t) cin>>arr[i];
#define print(arr) for(auto x: arr) cout<< x <<' '; cout<<'\n';
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second
#define MP make_pair
#define WINNING() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#ifndef ONLINE_JUDGE
#define debug(x) cerr << x<< endl;
#endif
ll expo(ll a, ll b, ll M) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % M; a = (a * a) % M; b = b >> 1;} return res;}
void fil(){ 
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);freopen("error.txt", "w", stderr); 
#endif
}
/*-------------------------------------------------------------------------------------------------------------------------------------*/

int ans(vector<vector<int> > &dp,string &a, string &b, string &c, int i, int j, int k){
    if(c.length()==k){
        return 0;
    }
    if(dp[i][j]!=-1) return dp[i][j];
    int fans = INT_MAX;
    if(i==a.length()){
        if(b[j]==c[k]){
            fans = min(fans, ans(dp, a, b, c, i, j+1, k+1));
        }
        else{
            fans = min(fans, ans(dp, a, b, c, i, j+1, k+1)+1);
        }
    }if(j==b.length()){
        if(a[i]==c[k]){
            fans = min(fans, ans(dp, a, b, c, i+1, j, k+1));
        }
        else{
            fans = min(fans, ans(dp, a, b, c, i+1, j, k+1)+1);
        }
    }
    if(j!=b.length() && i!=a.length()){
        if(a[i]==c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i+1, j, k+1), ans(dp, a, b, c, i, j+1, k+1)+1));
        }
        if(b[j]==c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i+1, j, k+1)+1, ans(dp, a, b, c, i, j+1, k+1)));
        }
        if(b[j]!=c[k] && a[i]!=c[k]){
            fans = min(fans, min(ans(dp, a, b, c, i, j+1, k+1)+1,  ans(dp, a, b, c, i+1, j, k+1)+1));
        }
    }
    return dp[i][j] = fans;
}

void solve(){
    string a, b, c;
    cin>>a>>b>>c;
    // cout<< a<<" "<<b<<" "<<c<<" ";
    vector<vector<int> > dp(a.length()+1, vector<int>(b.length()+1, -1));
    cout<<ans(dp, a, b, c, 0, 0, 0)<<"\n";
}

int main(){
    WINNING(); fil(); 
    ll t = 1;
    cin>>t;
    FA(i, 1, t+1){
        // cout << "Case #"<< i <<": ";
        solve(); 
        //cout<<"\n";
    }
}