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

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define inp(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define ll long long
const int inf = 1e18,mod=1e9+7;

int solve(string a, string b, string c, int i, int j, vector<vi> &dp) {
    if (i + j == c.size()) return 0;

    if (dp[i][j] != -1) return dp[i][j];

    if (i == a.size()) {
        int res = 0;
        for (; j < b.size(); j++) {
            if (b[j] == c[i + j]) res++;
        }
        return dp[i][j] = res;
    }

    if (j == b.size()) {
        int res = 0;
        for (; i < a.size(); i++) {
            if (a[i] == c[i + j]) res++;
        }
        return dp[i][j] = res;
    }

    if (a[i] == c[i + j]) {
        return dp[i][j] = max(1 + solve(a, b, c, i + 1, j,dp), solve(a, b, c, i, j + 1,dp));
    }

    if (b[j] == c[i + j]) {
        return dp[i][j] = max(solve(a, b, c, i + 1, j,dp), 1 + solve(a, b, c, i, j + 1,dp));
    }

    return dp[i][j] = max(solve(a, b, c, i + 1, j, dp), solve(a, b, c, i, j + 1, dp));
}


signed main(){ 
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        auto begin = chrono::high_resolution_clock::now();
        string a,b,c;
        cin>>a>>b>>c;
        int res=0;
        vector<vi> dp(a.size()+1,vi(b.size()+1,-1));
        cout<<c.size()-solve(a,b,c,0,0,dp)<<endl;

        auto end = chrono::high_resolution_clock::now();
        auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end - begin);
        cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds."<<endl;
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 16):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define inp(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define ll long long
const int inf = 1e18,mod=1e9+7;

int solve(string a, string b, string c, int i, int j, vector<vi> &dp) {
    if (i + j == c.size()) return 0;

    if (dp[i][j] != -1) return dp[i][j];

    if (i == a.size()) {
        int res = 0;
        for (; j < b.size(); j++) {
            if (b[j] == c[i + j]) res++;
        }
        return dp[i][j] = res;
    }

    if (j == b.size()) {
        int res = 0;
        for (; i < a.size(); i++) {
            if (a[i] == c[i + j]) res++;
        }
        return dp[i][j] = res;
    }

    if (a[i] == c[i + j] && b[j] == c[i + j]) {
        return dp[i][j] = max(1 + solve(a, b, c, i + 1, j,dp), 1 + solve(a, b, c, i, j + 1,dp));
    }

    if (a[i] == c[i + j]) {
        return dp[i][j] = max(1 + solve(a, b, c, i + 1, j,dp), solve(a, b, c, i, j + 1,dp));
    }

    if (b[j] == c[i + j]) {
        return dp[i][j] = max(solve(a, b, c, i + 1, j,dp), 1 + solve(a, b, c, i, j + 1,dp));
    }

    return dp[i][j] = max(solve(a, b, c, i + 1, j, dp), solve(a, b, c, i, j + 1, dp));
}


signed main(){ 
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        auto begin = chrono::high_resolution_clock::now();
        string a,b,c;
        cin>>a>>b>>c;
        int res=0;
        vector<vi> dp(a.size()+1,vi(b.size()+1,-1));
        cout<<c.size()-solve(a,b,c,0,0,dp)<<endl;

        auto end = chrono::high_resolution_clock::now();
        auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end - begin);
        cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds."<<endl;
    }
    return 0;
}