Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Compilation error):
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
using namespace std;
typedef long long ll;
typedef long double ld;

#define dbg(x) cout << #x << ' = ' << x << endl
#define all(x) (x).begin(), (x).end()
#define cin_vector(vec, n, T)  \
    vector<T> vec(n);          \
    for (ll i = 0; i < n; i++) \
        cin >> vec[i];

template <typename T>
void print(vector<T> &v)
{
    for (auto &a : v)
        cout << a << ' ';
    cout << endl;
}

string a, b, c;
int dp[10001][10001][10001];

int rec(int i, int j, int k)
{
    if (dp[i][j][k] != -1)
    {
        return dp[i][j][k];
    }
    int changes = 0;
    if (k == -1)
    {
        return 0;
    }
    if (i == -1)
    {
        if (b[j] == c[k])
        {
            return dp[i][j][k] = rec(i, j - 1, k - 1);
        }
        else
        {
            return dp[i][j][k] = 1 + rec(i, j - 1, k - 1);
        }
    }
    if (j == -1)
    {
        if (a[i] == c[k])
        {
            return dp[i][j][k] = rec(i - 1, j, k - 1);
        }
        else
        {
            return dp[i][j][k] = 1 + rec(i - 1, j, k - 1);
        }
    }
    if (a[i] == c[k] && b[j] != c[k])
    {
        return dp[i][j][k] = min(rec(i - 1, j, k - 1), 1 + rec(i, j - 1, k - 1));
    }
    if (b[j] == c[k] && a[i] != c[k])
    {
        return dp[i][j][k] = min(rec(i, j - 1, k - 1), 1 + rec(i - 1, j, k - 1));
    }
    if (a[i] == c[k] && b[j] == c[k])
    {
        return dp[i][j][k] = min(rec(i - 1, j, k - 1), rec(i, j - 1, k - 1));
    }
    else
    {
        changes++;
        return dp[i][j][k] = changes + min(rec(i - 1, j, k - 1), rec(i, j - 1, k - 1));
    }
}

void solve()
{
    memset(dp, -1, sizeof(dp));
    cin >> a >> b >> c;
    reverse(all(a));
    reverse(all(b));
    reverse(all(c));
    cout << rec(a.size() - 1, b.size() - 1, c.size() - 1) << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

Submission (verdict: Memory limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define dbg(x) cout << #x << ' = ' << x << endl
#define all(x) (x).begin(), (x).end()
#define cin_vector(vec, n, T)  \
    vector<T> vec(n);          \
    for (ll i = 0; i < n; i++) \
        cin >> vec[i];

template <typename T>
void print(vector<T> &v)
{
    for (auto &a : v)
        cout << a << ' ';
    cout << endl;
}

string a, b, c;
int dp[10007][10007];

int rec(int i, int j, int k)
{
    if (dp[i + 1][j + 1] != -1)
    {
        return dp[i + 1][j + 1];
    }
    int changes = 0;
    if (k == -1)
    {
        return 0;
    }
    if (i == -1)
    {
        if (b[j] == c[k])
        {
            return dp[i + 1][j + 1] = rec(i, j - 1, k - 1);
        }
        else
        {
            return dp[i + 1][j + 1] = 1 + rec(i, j - 1, k - 1);
        }
    }
    if (j == -1)
    {
        if (a[i] == c[k])
        {
            return dp[i + 1][j + 1] = rec(i - 1, j, k - 1);
        }
        else
        {
            return dp[i + 1][j + 1] = 1 + rec(i - 1, j, k - 1);
        }
    }
    if (a[i] == c[k] && b[j] != c[k])
    {
        return dp[i + 1][j + 1] = min(rec(i - 1, j, k - 1), 1 + rec(i, j - 1, k - 1));
    }
    if (b[j] == c[k] && a[i] != c[k])
    {
        return dp[i + 1][j + 1] = min(rec(i, j - 1, k - 1), 1 + rec(i - 1, j, k - 1));
    }
    if (a[i] == c[k] && b[j] == c[k])
    {
        return dp[i + 1][j + 1] = min(rec(i - 1, j, k - 1), rec(i, j - 1, k - 1));
    }
    else
    {
        changes++;
        return dp[i + 1][j + 1] = changes + min(rec(i - 1, j, k - 1), rec(i, j - 1, k - 1));
    }
}

void solve()
{
    memset(dp, -1, sizeof(dp));
    cin >> a >> b >> c;
    int a1 = a.size();
    int b1 = b.size();
    int c1 = c.size();
    reverse(all(a));
    reverse(all(b));
    reverse(all(c));
    cout << rec(a1 - 1, b1 - 1, c1 - 1) << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}