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

Previous submission (verdict: Time limit exceeded on test 16):
// Problem: E. Three Strings
// Contest: Codeforces - Codeforces Round 991 (Div. 3)
// URL: https://codeforces.com/contest/2050/problem/E
// Memory Limit: 256 MB
// Time Limit: 2500 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define PIKACHU {ios_base::sync_with_stdio(0); cin.tie(0);}
#define MOD 1000000007
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define mp make_pair
#define it(x) (x).begin(), (x).end()
#define lo(a) for(auto ptr: a) cout<<ptr<<" "; cout<<endl;
#define loo(a,s,e) for(int i=s;i<=e;i++) cout<<a[i]<<" "; cout<<endl;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
int rec(int i,int j,string a,string b,string c,vector<vector<int>>&dp){
	if(i==a.length()&&j==b.length()) return 0;
	if(dp[i][j]!=-1) return  dp[i][j];
	int ans=10000007;
	if(i<a.length()){
		if(a[i]!=c[i+j])
		ans=min(ans,1+rec(i+1,j,a,b,c,dp));
		else if(a[i]==c[i+j])
		ans=min(ans,rec(i+1,j,a,b,c,dp));
	}
	if(j<b.length()){
		if(b[j]!=c[i+j])
		ans=min(ans,1+rec(i,j+1,a,b,c,dp));
		else if(b[j]==c[i+j])
		ans=min(ans,rec(i,j+1,a,b,c,dp));
	}
	return dp[i][j]=ans;
}
int32_t main(){
	PIKACHU;
	int t;
cin >> t;
while(t--){
	string a,b,c;
	cin >> a >> b >> c;
	vector<vector<int>>dp(a.size()+1,vector<int>(b.size()+1,-1));
	cout << rec(0,0,a,b,c,dp) << endl;
}
}

Submission (verdict: Accepted):
// Problem: E. Three Strings
// Contest: Codeforces - Codeforces Round 991 (Div. 3)
// URL: https://codeforces.com/contest/2050/problem/E
// Memory Limit: 256 MB
// Time Limit: 2500 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define PIKACHU {ios_base::sync_with_stdio(0); cin.tie(0);}
#define MOD 1000000007
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define mp make_pair
#define it(x) (x).begin(), (x).end()
#define lo(a) for(auto ptr: a) cout<<ptr<<" "; cout<<endl;
#define loo(a,s,e) for(int i=s;i<=e;i++) cout<<a[i]<<" "; cout<<endl;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
int rec(int i,int j,string &a,string &b,string &c,vector<vector<int>>&dp){
	if(i==a.length()&&j==b.length()) return 0;
	if(dp[i][j]!=-1) return  dp[i][j];
	int ans=1e9;
	if(i<a.length()){
		if(a[i]==c[i+j])
		ans=min(ans,rec(i+1,j,a,b,c,dp));
		else
		ans=min(ans,1+rec(i+1,j,a,b,c,dp));
		
	}
	if(j<b.length()){
		if(b[j]==c[i+j])
		ans=min(ans,rec(i,j+1,a,b,c,dp));
		else
		ans=min(ans,1+rec(i,j+1,a,b,c,dp));
	}
	return dp[i][j]=ans;
}
int32_t main(){
	PIKACHU;
	int t;
cin >> t;
while(t--){
	string a,b,c;
	cin >> a >> b >> c;
	vector<vector<int>>dp(a.size()+1,vector<int>(b.size()+1,-1));
	cout << rec(0,0,a,b,c,dp) << endl;
}
}