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

Previous submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
#define int long long int
#define pii pair<int,int>
#define fr(var_nam,initial_val,till) for(int var_nam=initial_val;var_nam<till;var_nam++)
#define max(a,b) max((int)a,(int)b)
#define pow powl
#define vi vector<int>
#define sqrt sqrtl
#define pb push_back
#define double_out(a) cout<<fixed<<setprecision(a);
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define fill(dp,INIT_VALUE) memset(dp, (int)INIT_VALUE, sizeof(dp));
#define take_inp(vec) fr(i,0,vec.size())cin>>vec[i];
using namespace std;
const int INF = 1e18;
const int MOD = 1e9+7;
const int LOGD=30;
const double ESP = (1.0/(double)(1e10));
const int N=2e5+5;
vector<bool> SieveOfEratosthenes(int n) {vector<bool> prime(n + 1, true);prime[0] = prime[1] = false;for (int p = 2; p * p <= n; p++) {if (prime[p] == true) {for (int i = p * p; i <= n; i += p) {prime[i] = false;}}}return prime;}
void print_vec(vector<int> vec){for(auto a:vec)cout<<a<<' ';}
void print_arr(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<' ';cout<<endl;}
bool pair_equals(pii p1,pii p2){bool res=false;res= (p1.first==p2.first && p2.second==p1.second);return res;}
void print_pair(pair<int,int> p1){cout<<p1.first<<' '<< p1.second<<endl;}
int power(int a, int b, int m) { a %= m; if (a==1 || b==0)return 1; int res=power(a,b/2,m); res%=m; if (b%2==1){ return ((res*res)%m*a)%m; } return (res*res)%m; }
unsigned long long modInverse(unsigned long long n,int p){return power(n, p - 2, p);}
unsigned long long nCrModPFermat(unsigned long long n,int r, int p){if (n < r)return 0;if (r == 0)return 1;unsigned long long fac[n + 1];fac[0] = 1;for (int i = 1; i <= n; i++)fac[i] = (fac[i - 1] * i) % p;return (fac[n] * modInverse(fac[r], p) % p* modInverse(fac[n - r], p) % p)% p;}
int mod_mul(int a,int b){return (a*b)%MOD;}
int mod_add(int a,int b){return (a+b)%MOD;}
int mod_sub(int a,int b){return (a-b)%MOD;}
int mod_div(int a,int b){return mod_mul(a,modInverse(b,MOD));}


int solve(int i,int j,vector<vi> &dp,string &a,string &b,string &c){
    if(i+j>=c.size())return 0;
    if(dp[i][j]!=-1)return dp[i][j];
    int ans=INF;
    if(i<a.size()){
        if(a[i]==c[i+j])ans=solve(i+1,j,dp,a,b,c);
        else ans = min(ans,solve(i+1,j,dp,a,b,c)+1);
        if(j<b.size())ans=min(ans,solve(i,j+1,dp,a,b,c)+1);
    }
    if(j<b.size()){
        if(b[j]==c[i+j])ans=solve(i,j+1,dp,a,b,c);
        else ans=min(ans,solve(i,j+1,dp,a,b,c)+1);
        if(i<a.size())ans=min(ans,solve(i+1,j,dp,a,b,c)+1);
    }
    dp[i][j]=ans;
    return ans;
}

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test=1;
  #ifndef ONLINE_JUDGE
  //  freopen("in.txt", "r", stdin);
  //  freopen("out.txt", "w", stdout);
  #endif
  cin>>test;
  for(int _=0;_<test;_++){
    string a,b,c;
    cin>>a>>b>>c;
    // cout<<"Strings "<<a<<" "<<b<<" "<<c<<endl;
    vector<vi> dp(a.size()+1, vi(b.size()+1, -1));
    int ans = solve(0,0,dp,a,b,c);
    cout<<ans<<endl;
  }
  return 0;
}

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

const int INF = 1e15;

int solve(int i, int j, vector<vector<int>> &dp, string &a, string &b, string &c) {
    if (i + j >= c.size()) return 0;
    if (dp[i][j] != -1) return dp[i][j];
    int ans = INF;
    if (i < a.size()) {
        int cost = (a[i] != c[i + j]);
        ans = min(ans, solve(i + 1, j, dp, a, b, c) + cost);
    }
    if (j < b.size()) {
        int cost = (b[j] != c[i + j]);
        ans = min(ans, solve(i, j + 1, dp, a, b, c) + cost);
    }
    dp[i][j] = ans;
    return ans;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int test;
    cin >> test;
    while (test--) {
        string a, b, c;
        cin >> a >> b >> c;
        vector<vector<int>> dp(a.size() + 1, vector<int>(b.size() + 1, -1));
        int ans = solve(0, 0, dp, a, b, c);
        cout << ans << endl;
    }

    return 0;
}