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

Previous submission (verdict: Memory limit exceeded on test 14):
#include <bits/stdc++.h>
#define ll long long 
#define pi pair<ll,ll>
#define vi vector<ll> 
#define dd double
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define lcm(a, b) ((a) * (b)) / __gcd(a, b)
#define mp make_pair
#define in insert
#define fi first
#define lb lower_bound
#define ub upper_bound
#define se second
#define yes cout<<"YES"
#define no cout<<"NO"
#define rd(n) ll n; cin>>n;
#define all(v) (v).begin(),(v).end()
#define ra(a,n) vi a(n); f(i,0,n){cin>>a[i];}
const int mod = 1e9 + 7;
using namespace std;
#define int long long

int n, m;

int fun(string a, string b, string c, int i, int j, vector<vector<vector<int>>>& dp) {
    if (i >= n && j >= m) return 0;
    if (dp[i][j][i + j] != -1) return dp[i][j][i + j];
    int ans = 1e5;
    if (i < n) {
        if (a[i] != c[i + j]) {
            ans = min(ans, fun(a, b, c, i + 1, j, dp) + 1);
        } else {
            ans = min(ans, fun(a, b, c, i + 1, j, dp));
        }
    }
    if (j < m) {
        if (b[j] != c[i + j]) {
            ans = min(ans, fun(a, b, c, i, j + 1, dp) + 1);
        } else {
            ans = min(ans, fun(a, b, c, i, j + 1, dp));
        }
    }
    return dp[i][j][i + j] = ans;
}

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    n = a.size(), m = b.size();
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(n + m + 1, -1)));
    
    
    cout << fun(a, b, c, 0, 0, dp);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long t = 1;
    cin >> t;
    while (t--) {
        solve();
        cout << endl;
    }
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long 
#define pi pair<ll,ll>
#define vi vector<ll> 
#define dd double
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define lcm(a, b) ((a) * (b)) / __gcd(a, b)
#define mp make_pair
#define in insert
#define fi first
#define lb lower_bound
#define ub upper_bound
#define se second
#define yes cout<<"YES"
#define no cout<<"NO"
#define rd(n) ll n; cin>>n;
#define all(v) (v).begin(),(v).end()
#define ra(a,n) vi a(n); f(i,0,n){cin>>a[i];}
const int mod = 1e9 + 7;
using namespace std;
#define int long long

int n, m;

int fun(string a, string b, string c, int i, int j, vector<vector<vector<int>>>& dp) {
    if (i >= n && j >= m) return 0;
    if (dp[i][j][i + j] != -1) return dp[i][j][i + j];
    int ans = 1e5;
    if (i < n) {
        if (a[i] != c[i + j]) {
            ans = min(ans, fun(a, b, c, i + 1, j, dp) + 1);
        } else {
            ans = min(ans, fun(a, b, c, i + 1, j, dp));
        }
    }
    if (j < m) {
        if (b[j] != c[i + j]) {
            ans = min(ans, fun(a, b, c, i, j + 1, dp) + 1);
        } else {
            ans = min(ans, fun(a, b, c, i, j + 1, dp));
        }
    }
    return dp[i][j][i + j] = ans;
}

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    n = a.size(), m = b.size();
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(n + m + 1, -1)));
    // cout << fun(a, b, c, 0, 0, dp);
    dp[0][0][0] = 0;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            for (int k = 0; k <= n + m; k++) {
                if (i + j != k) continue;
                if (i < n && k < n + m) {
                    dp[i + 1][j][k + 1] = min(dp[i + 1][j][k + 1], dp[i][j][k] + (a[i] != c[k]));
                }
                if (j < m && k < n + m) {
                    dp[i][j + 1][k + 1] = min(dp[i][j + 1][k + 1], dp[i][j][k] + (b[j] != c[k]));
                }
            }
        }
    }

    cout << dp[n][m][n + m];
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long t = 1;
    cin >> t;
    while (t--) {
        solve();
        cout << endl;
    }
    return 0;
}