Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
    
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define all(v)                ((v).begin()), ((v).end())
#define allr(v)                ((v).rbegin()), ((v).rend())
#define sz(v)                ((int)((v).size()))
#define clr(v, d)            memset(v, d, sizeof(v))
#define rep(i, v)        for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define ceils(x, y) (x + y - 1) / y

//for pairs
#define pii pair<int, int>
#define vii vector<pii>

const double EPS = (1e-7);
int dcmp(double x, double y) {    return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;    }
int fix(int a,int n) {
    return (a % n + n) % n;
}

#define pb                    push_back
#define MP                    make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
typedef long double         ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

#define sumv(v) accumulate(all(v), 0ll)
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))


// Handling vector, vector of pairs
template <typename T1, typename T2> // cin >> pair<T1, T2>
istream& operator>>(istream& istream, pair<T1, T2>& p){return (istream >> p.first >> p.second);}
template <typename T1, typename T2> // cout << pair<T1, T2>
ostream& operator<<(ostream& ostream, const pair<T1, T2>& p){return (ostream << p.first << " " << p.second);}
template<typename T> // cin >> vector<T>
istream& operator>>(istream &in, vector<T> &v){for(auto &it: v) cin >> it; return in;}
template<typename T> //cout << vector<T>
ostream& operator<<(ostream &out, const vector<T> &c){for (auto &it: c) cout << it << " "; return out;}

int binpow(int a, int b) {int res = 1;while (b > 0) {if (b & 1)res = res * a;a = a * a;b >>= 1;}return res;}

int gcd (int a, int b) { while (b) {a %= b;swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int int_sqrt (long long x) {int ans = 0;for (int k = 1LL << 30; k != 0; k /= 2) {if ((ans + k) * (ans + k) <= x) {ans += k;}}return ans;}
bool isOverflow(int x, int y){return (x > LLONG_MAX / y or y > LLONG_MAX / x);}

const int mod = 1e9 + 7;
 
int inv(int i) {if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;}
int mod_mul(int a, int b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
int mod_add(int a, int b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}


const int inf=1e18;



int solve(){
string a,b, c;
cin >> a>>b>>c;

int n=sz(c) ;
int aa=sz(a) ;
int bb=sz(b) ;

function<int(int, int, int) >fun=[&](int i , int x, int y) {
if(i>=n) return 0ll;
if(x>=aa && y>=bb) return 0ll;
if(x>=aa) 
return (int)( (c[i]!=b[y])+fun(i+1,x, y+1)) ;

if(y>=bb) 
return (int) ((c[i]!=a[x])+fun(i+1,x+1, y)) ;

int ch1= (c[i]!=b[y])+fun(i+1,x, y+1);
int ch2= (c[i]!=a[x])+fun(i+1,x+1, y);
return min(ch1, ch2) ;


};

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

}

signed main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

int t=1;
cin>>t;
while(t--)
{
    solve();
    cout<<"\n";
}

    return 0;
}

Submission (verdict: Memory limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define all(v)                ((v).begin()), ((v).end())
#define allr(v)                ((v).rbegin()), ((v).rend())
#define sz(v)                ((int)((v).size()))
#define clr(v, d)            memset(v, d, sizeof(v))
#define rep(i, v)        for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define ceils(x, y) (x + y - 1) / y

#define pii pair<int, int>
#define vii vector<pii>

const double EPS = (1e-7);
int dcmp(double x, double y) {    return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;    }
int fix(int a,int n) {
    return (a % n + n) % n;
}

#define pb                    push_back
#define MP                    make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
typedef long double         ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

#define sumv(v) accumulate(all(v), 0ll)
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))

template <typename T1, typename T2>
istream& operator>>(istream& istream, pair<T1, T2>& p){return (istream >> p.first >> p.second);}
template <typename T1, typename T2>
ostream& operator<<(ostream& ostream, const pair<T1, T2>& p){return (ostream << p.first << " " << p.second);}
template<typename T>
istream& operator>>(istream &in, vector<T> &v){for(auto &it: v) cin >> it; return in;}
template<typename T>
ostream& operator<<(ostream &out, const vector<T> &c){for (auto &it: c) cout << it << " "; return out;}

int binpow(int a, int b) {int res = 1;while (b > 0) {if (b & 1)res = res * a;a = a * a;b >>= 1;}return res;}

int gcd (int a, int b) { while (b) {a %= b;swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int int_sqrt (long long x) {int ans = 0;for (int k = 1LL << 30; k != 0; k /= 2) {if ((ans + k) * (ans + k) <= x) {ans += k;}}return ans;}
bool isOverflow(int x, int y){return (x > LLONG_MAX / y or y > LLONG_MAX / x);}

const int mod = 1e9 + 7;

int inv(int i) {if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;}
int mod_mul(int a, int b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
int mod_add(int a, int b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}

const int inf=1e18;

int solve(){
string a,b,c;
cin >> a>>b>>c;

int n=sz(c);
int aa=sz(a);
int bb=sz(b);

vector<vector<vector<int>>> dp(n, vector<vector<int>>(aa + 1, vector<int>(bb + 1, -1)));

function<int(int, int, int)> fun = [&](int i, int x, int y) {
if(i >= n) return 0ll;
if(x >= aa && y >= bb) return 0ll;
if(dp[i][x][y] != -1) return dp[i][x][y];
if(x >= aa)
return dp[i][x][y] = (int)((c[i] != b[y]) + fun(i + 1, x, y + 1));
if(y >= bb)
return dp[i][x][y] = (int)((c[i] != a[x]) + fun(i + 1, x + 1, y));

int ch1 = (c[i] != b[y]) + fun(i + 1, x, y + 1);
int ch2 = (c[i] != a[x]) + fun(i + 1, x + 1, y);
return dp[i][x][y] = min(ch1, ch2);
};

int ans = fun(0, 0, 0);
cout << ans;
return 0;
}

signed main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

int t=1;
cin>>t;
while(t--)
{
    solve();
    cout<<"\n";
}

    return 0;
}