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

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

using ll = long long;
using lld = long double;
using ull = unsigned long long;

const lld pi = 3.141592653589793238;
const ll INF = LONG_LONG_MAX;
const ll mod = 1e9 + 7;

#define ff first
#define ss second
#define pb push_back
#define fl(i, n) for (ll i = 0; i < n; i++)
#define py cout << "YES\n";
#define pm cout << "-1\n";
#define pn cout << "NO\n";
#define pimp cout << "IMPOSSIBLE\n";
#define all(x) (x).begin(), (x).end()
#define input(a, n) for (ll i = 0; i < n; i++) cin >> a[i]


ll solver(ll p1,ll p2,ll pos, string a, string b, string c,vector<vector<vector<ll>>>&dp){

    if(p1==a.size()){

        ll count=0;
        for(ll i=p2;i<b.size();i++){

            if(b[i]!=c[pos])count++;

            pos++;
        }

        return count;
    }

    if(p2==b.size()){

        ll count=0;
        for(ll i=p1;i<a.size();i++){

            if(a[i]!=c[pos])count++;

            pos++;
        }

        return count;
    }

    if(dp[p1][p2][pos]!=-1)return dp[p1][p2][pos];

    dp[p1][p2][pos]=1e9;

    if(a[p1]==c[pos]){

        dp[p1][p2][pos] = min(dp[p1][p2][pos], solver(p1+1,p2,pos+1,a,b,c,dp));
    }

    else{

        dp[p1][p2][pos]= min(dp[p1][p2][pos],1+solver(p1+1,p2,pos+1,a,b,c,dp));
    }

    if(b[p2]==c[pos]){

        dp[p1][p2][pos] = min(dp[p1][p2][pos], solver(p1,p2+1,pos+1,a,b,c,dp));
    }

    else{

        dp[p1][p2][pos]= min(dp[p1][p2][pos],1+solver(p1,p2+1,pos+1,a,b,c,dp));

    }

    return dp[p1][p2][pos];
}

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

    ll t;
    cin >> t;

    while (t--) {
        
        string a,b,s;

        cin>>a>>b>>s;

        ll p1=a.size();

        ll p2=b.size();

        vector<vector<vector<ll>>>dp(p1+1,vector<vector<ll>>(p2+1,vector<ll>(p1+p2+1,-1)));


        solver(0ll , 0ll, 0ll, a, b, s, dp);

        cout<<dp[0][0][0]<<endl;
        
        
    }

    return 0;
}


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

using ll = long long;
using lld = long double;
using ull = unsigned long long;

const lld pi = 3.141592653589793238;
const ll INF = LONG_LONG_MAX;
const ll mod = 1e9 + 7;

#define ff first
#define ss second
#define pb push_back
#define fl(i, n) for (ll i = 0; i < n; i++)
#define py cout << "YES\n";
#define pm cout << "-1\n";
#define pn cout << "NO\n";
#define pimp cout << "IMPOSSIBLE\n";
#define all(x) (x).begin(), (x).end()
#define input(a, n) for (ll i = 0; i < n; i++) cin >> a[i]


ll solver(ll p1,ll p2,ll pos, string& a, string& b, string& c,vector<vector<vector<ll>>>&dp){

    if(p1==a.size()){

        ll count=0;
        for(ll i=p2;i<b.size();i++){

            if(b[i]!=c[pos])count++;

            pos++;
        }

        return count;
    }

    if(p2==b.size()){

        ll count=0;
        for(ll i=p1;i<a.size();i++){

            if(a[i]!=c[pos])count++;

            pos++;
        }

        return count;
    }

    if(dp[p1][p2][pos]!=-1)return dp[p1][p2][pos];

    dp[p1][p2][pos]=1e9;

    if(a[p1]==c[pos]){

        dp[p1][p2][pos] = min(dp[p1][p2][pos], solver(p1+1,p2,pos+1,a,b,c,dp));
    }

    else{

        dp[p1][p2][pos]= min(dp[p1][p2][pos],1+solver(p1+1,p2,pos+1,a,b,c,dp));
    }

    if(b[p2]==c[pos]){

        dp[p1][p2][pos] = min(dp[p1][p2][pos], solver(p1,p2+1,pos+1,a,b,c,dp));
    }

    else{

        dp[p1][p2][pos]= min(dp[p1][p2][pos],1+solver(p1,p2+1,pos+1,a,b,c,dp));

    }

    return dp[p1][p2][pos];
}

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

    ll t;
    cin >> t;

    while (t--) {
        
        string a,b,s;

        cin>>a>>b>>s;

        ll p1=a.size();

        ll p2=b.size();

        vector<vector<vector<ll>>>dp(p1+1,vector<vector<ll>>(p2+1,vector<ll>(p1+p2+1,-1)));


        solver(0ll , 0ll, 0ll, a, b, s, dp);

        cout<<dp[0][0][0]<<endl;
        
        
    }

    return 0;
}