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

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define  ull unsigned long long 
#define int long long

int32_t main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

	ull t;cin >> t;
    
    while (t--) {
        
        string a, b, c; cin >>a >> b >> c;
        int l1 = a.length(),l2=b.length(),l3=c.length();
        vector<int> prev(l3,0),curr(l3);
        for (int i = 0;i < l1;i++) {
            for (int j = 0;j < l3;j++) {
                if (j != 0){
                    if (a[i] == c[j]) curr[j] = 1 + prev[j - 1];
                    else curr[j] = max(curr[j - 1], prev[j]);
                }
                else {
                    if (a[i] == c[j]) curr[j] = 1 ;
                    else curr[j] = prev[j];
                }
                
            }
            prev = curr;
        }
        int a1 = curr[l3 - 1];string n;
        int count = 0;vector<int>r;
        for (int j = 0;j < l3;j++) {
            if (curr[j] <=count) {
                
                n += string(1,c[j]);
            }
            else count = curr[j];
        }
        l3 = n.size();
        vector<int> prev1(l3, 0), curr1(l3);
        for (int i = 0;i < l2;i++) {
            for (int j = 0;j < l3;j++) {
                if (j != 0) {
                    if (b[i] == n[j]) curr1[j] = 1 + prev1[j - 1];
                    else curr1[j] = max(curr1[j - 1], prev1[j]);
                }
                else {
                    if (b[i] == n[j]) curr1[j] = 1;
                    else curr1[j] = prev1[j];
                }

            }
            prev1 = curr1;
        }
        int a2 = curr1[l3 - 1];
        cout << c.size() - a1 - a2<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define  ull unsigned long long 
#define int long long

int32_t main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

	ull t;cin >> t;
    
    while (t--) {
        
        string a, b, c; cin >>a >> b >> c;
        int x = a.length();
        int y = b.length();
        int z = c.length();
        vector<vector<int>> dp(x+1, vector<int>(y+1));
        dp[0][0] = 0;
        for (int i = 1;i <= x;i++) dp[i][0] = dp[i - 1][0] + (int)(a[i - 1] != c[i - 1]);
        for (int j = 1;j <= y;j++) dp[0][j] = dp[0][j-1] + (int)(b[j - 1] != c[j - 1]);
        for (int i = 1;i <= x;i++) {
            for (int j = 1;j <= y;j++) {
                if (c[i + j - 1] != a[i - 1] && c[i + j - 1] != b[j - 1]) {
                    dp[i][j] = min(dp[i - 1][j]+1, dp[i][j - 1]+1);
                }
                if (c[i + j - 1] == a[i - 1] && c[i + j - 1] != b[j - 1]) {
                    dp[i][j] = min(dp[i - 1][j] , dp[i][j - 1] + 1);
                }
                if (c[i + j - 1] != a[i - 1] && c[i + j - 1] == b[j - 1]) {
                    dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] );
                }
                if (c[i + j - 1] == a[i - 1] && c[i + j - 1] == b[j - 1]) {
                    dp[i][j] = min(dp[i - 1][j] , dp[i][j - 1] );
                }
            }
        }
        cout << dp[x][y] << endl;


    }
    return 0;
}