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

Previous 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;
}


Submission (verdict: Accepted):
#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

const int inf = 1e9;

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    int n = a.size(), m = b.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, inf));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = dp[i][0] + (a[i] != c[i]);
    }
    for (int j = 0; j < m; j++) {
        dp[0][j + 1] = dp[0][j] + (b[j] != c[j]);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != c[i + j - 1]),
                           dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));
        }
    }
    cout << dp[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;
}