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

Previous submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define lld  long double
#define fn(n) for (int i = 0; i < n; i++)
#define f(i, x, n) for (int i = x; i < n; i++)
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define cyes cout<<"YES"<<"\n"
#define cno cout<<"NO"<<"\n"
#define vi vector<int>
#define vll vector<ll>
#define inf 2147483647
#define msdfan ios_base::sync_with_stdio(false);cin.tie(NULL);
const int mod = 1e9+7;
const int N = 3000 + 2;
template <typename T>
void printv(const T &t){{std::copy(t.cbegin(), t.cend(), std::ostream_iterator<typename T::value_type>(std::cout, " "));  }  cout << "\n";}
template <class T>
void cc(T a) { cout << a << "\n"; } 
template <class T>
void kk(T a) { cout << a << " "; }


int dp[N][N];


int func(int i,int j,string &a,string &b,string &c){
    if(dp[i][j] != -1) return dp[i][j];
    if(i == a.size()){
        int d = 0,k = j;
        while(k < b.size()){
             int currInd = i + k;
             d += (b[k] != c[currInd]);
             k++;
        }
        return dp[i][j] = d;
    }
    else if(j == b.size()){
        int d = 0,k = i;
        while(k < a.size()){
             int currInd = k + j;
             d += (a[k] != c[currInd]);
             k++;
        }
        return dp[i][j] =  d;
    }
    
    int fromA = 1e14,fromB = 1e14;

    if(i < a.size()){
        int currInd = i + j;
        fromA = (c[currInd] != a[i]) + func(i+1,j,a,b,c);
    }
    if(j < b.size()){
        int currInd = i + j;
        fromB = (c[currInd] != b[j]) + func(i,j+1,a,b,c);
    }

    return dp[i][j] = min(fromA,fromB);
}

void solve(){
string a,b,c;
cin >> a >> b >> c;

memset(dp,-1,sizeof(dp));

cc(func(0,0,a,b,c));
}




int32_t main(){
msdfan;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif


int tt = 1;
cin >> tt;

for(int i = 0; i < tt; i++){
    solve();
}


return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define lld  long double
#define fn(n) for (int i = 0; i < n; i++)
#define f(i, x, n) for (int i = x; i < n; i++)
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define cyes cout<<"YES"<<"\n"
#define cno cout<<"NO"<<"\n"
#define vi vector<int>
#define vll vector<ll>
#define inf 2147483647
#define msdfan ios_base::sync_with_stdio(false);cin.tie(NULL);
const int mod = 1e9+7;
const int N = 3000 + 2;
template <typename T>
void printv(const T &t){{std::copy(t.cbegin(), t.cend(), std::ostream_iterator<typename T::value_type>(std::cout, " "));  }  cout << "\n";}
template <class T>
void cc(T a) { cout << a << "\n"; } 
template <class T>
void kk(T a) { cout << a << " "; }





int func(int i,int j,string &a,string &b,string &c,vector<vector<int>> &dp){
    if(dp[i][j] != -1) return dp[i][j];
    if(i == a.size()){
        int d = 0,k = j;
        while(k < b.size()){
             int currInd = i + k;
             d += (b[k] != c[currInd]);
             k++;
        }
        return dp[i][j] = d;
    }
    else if(j == b.size()){
        int d = 0,k = i;
        while(k < a.size()){
             int currInd = k + j;
             d += (a[k] != c[currInd]);
             k++;
        }
        return dp[i][j] =  d;
    }
    
    int fromA = 1e14,fromB = 1e14;

    if(i < a.size()){
        int currInd = i + j;
        fromA = (c[currInd] != a[i]) + func(i+1,j,a,b,c,dp);
    }
    if(j < b.size()){
        int currInd = i + j;
        fromB = (c[currInd] != b[j]) + func(i,j+1,a,b,c,dp);
    }

    return dp[i][j] = min(fromA,fromB);
}

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,-1));

cc(func(0,0,a,b,c,dp));
}




int32_t main(){
msdfan;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif


int tt = 1;
cin >> tt;

for(int i = 0; i < tt; i++){
    solve();
}


return 0;
}