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

Previous submission (verdict: Wrong answer on test 2):
#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 rec(int i, int j, int k)
{
    int changes = 0;
    if (k == -1)
    {
        return 0;
    }
    if (a[i] == c[k] && b[j] != c[k])
    {
        return min(rec(i - 1, j, k - 1), 1 + rec(i, j - 1, k - 1));
    }
    if (b[j] == c[k] && a[i] != c[k])
    {
        return min(rec(i, j - 1, k - 1), 1 + rec(i - 1, j, k - 1));
    }
    if (a[i] == c[k] && b[j] == c[k])
    {
        return min(rec(i - 1, j, k - 1), rec(i, j - 1, k - 1));
    }
    else
    {
        changes++;
        return changes + min(rec(i - 1, j, k - 1), rec(i, j - 1, k - 1));
    }
}

void solve()
{

    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: Time limit exceeded on test 6):
#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 rec(int i, int j, int k)
{
    int changes = 0;
    if (k == -1)
    {
        return 0;
    }
    if (i == -1)
    {
        if (b[j] == c[k])
        {
            return rec(i, j - 1, k - 1);
        }
        else
        {
            return 1 + rec(i, j - 1, k - 1);
        }
    }
    if (j == -1)
    {
        if (a[i] == c[k])
        {
            return rec(i - 1, j, k - 1);
        }
        else
        {
            return 1 + rec(i - 1, j, k - 1);
        }
    }
    if (a[i] == c[k] && b[j] != c[k])
    {
        return min(rec(i - 1, j, k - 1), 1 + rec(i, j - 1, k - 1));
    }
    if (b[j] == c[k] && a[i] != c[k])
    {
        return min(rec(i, j - 1, k - 1), 1 + rec(i - 1, j, k - 1));
    }
    if (a[i] == c[k] && b[j] == c[k])
    {
        return min(rec(i - 1, j, k - 1), rec(i, j - 1, k - 1));
    }
    else
    {
        changes++;
        return changes + min(rec(i - 1, j, k - 1), rec(i, j - 1, k - 1));
    }
}

void solve()
{

    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();
    }
}