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

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
#define int long long
#define fastio() ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int dp[1001][1001];
int solve(int indexa,int indexb,int indexc,string a,string b,string c){
    int mine=INT_MAX;
     if(indexa<(int)a.size() && indexb>=(int)b.size()){
           if(c[indexc]!=a[indexa]){
                if(dp[indexa+1][indexb]==-1){
                    dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c);
                }
                mine=min(mine,1+dp[indexa+1][indexb]);
           }
           else{
                if(dp[indexa+1][indexb]==-1){
                    dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c);
                }
                mine=min(mine,dp[indexa+1][indexb]);
           }
     }
     else if(indexa>=(int)a.size() && indexb<(int)b.size()){
            if(c[indexc]!=b[indexb]){
                if(dp[indexa][indexb+1]==-1){
                    dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c);
                }
                mine=min(mine,1+dp[indexa][indexb+1]);
           }
           else{
                if(dp[indexa][indexb+1]==-1){
                    dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c);
                }
                mine=min(mine,dp[indexa][indexb+1]);
           }
     }
     else if(indexa<(int)a.size() && indexb<(int)b.size()){
                 if(c[indexc]!=a[indexa]){
                    if(dp[indexa+1][indexb]==-1){
                        dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c);
                    }
                    mine=min(mine,1+dp[indexa+1][indexb]);
                 }
                 else{
                    if(dp[indexa+1][indexb]==-1){
                        dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c);
                    }
                    mine=min(mine,dp[indexa+1][indexb]);
                 }
                 if(c[indexc]!=b[indexb]){
                     if(dp[indexa][indexb+1]==-1){
                        dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c);
                    }
                    mine=min(mine,1+dp[indexa][indexb+1]);
                 }
                 else{
                      if(dp[indexa][indexb+1]==-1){
                        dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c);
                    }
                    mine=min(mine,dp[indexa][indexb+1]);
                 }
     }
     else{
        mine=min(mine,(int)0);
     }
     return mine;
}
int32_t main(){
    fastio();
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int indexa=0,indexb=0,indexc=0;;
        memset(dp,-1,sizeof(dp));
        dp[indexa][indexb]=solve(indexa,indexb,indexc,a,b,c);
        cout<<dp[indexa][indexb]<<"\n";
    }
}

Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
#define int long long
#define fastio() ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int dp[1001][1001];
int solve(int indexa,int indexb,int indexc,string a,string b,string c){
    int mine=INT_MAX;
     if(indexa<(int)a.size() && indexb>=(int)b.size()){
           int count=0;
           int j=indexa;
           for(int i=indexc;i<(int)c.size();i++){
                 if(c[i]!=a[j]){
                    count++;
                 }
                 j++;
           }
           mine=min(mine,count);
     }
     else if(indexa>=(int)a.size() && indexb<(int)b.size()){
           int count=0;
           int j=indexb;
           for(int i=indexc;i<(int)c.size();i++){
                 if(c[i]!=b[j]){
                    count++;
                 }
                 j++;
           }
           mine=min(mine,count);
     }
     else if(indexa<(int)a.size() && indexb<(int)b.size()){
                 if(c[indexc]!=a[indexa]){
                    if(dp[indexa+1][indexb]==-1){
                        dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c);
                    }
                    mine=min(mine,1+dp[indexa+1][indexb]);
                 }
                 else{
                    if(dp[indexa+1][indexb]==-1){
                        dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c);
                    }
                    mine=min(mine,dp[indexa+1][indexb]);
                 }
                 if(c[indexc]!=b[indexb]){
                     if(dp[indexa][indexb+1]==-1){
                        dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c);
                    }
                    mine=min(mine,1+dp[indexa][indexb+1]);
                 }
                 else{
                      if(dp[indexa][indexb+1]==-1){
                        dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c);
                    }
                    mine=min(mine,dp[indexa][indexb+1]);
                 }
     }
     else{
        mine=min(mine,(int)0);
     }
     return mine;
}
int32_t main(){
    fastio();
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int indexa=0,indexb=0,indexc=0;
        memset(dp,-1,sizeof(dp));
        dp[indexa][indexb]=solve(indexa,indexb,indexc,a,b,c);
        cout<<dp[indexa][indexb]<<"\n";
    }
}