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()){
           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";
    }
}

Submission (verdict: Accepted):
#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;
int32_t main(){
    fastio();
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        //just tabulate
        vector<vector<int>>dp((int)a.size()+1,vector<int>((int)b.size()+1));
        for(int i=(int)b.size()-1;i>=0;i--){
               int indexc=(int)c.size()-(int)b.size()+i;
               int x=0;
               if(c[indexc]!=b[i]){
               x=1;
               }
               dp[(int)a.size()][i]=x+dp[(int)a.size()][i+1];
        }
        for(int i=(int)a.size()-1;i>=0;i--){
            int indexc=(int)c.size()-(int)a.size()+i;
            int x=0;
            if(c[indexc]!=a[i]){
                x=1;
            }
            dp[i][(int)b.size()]=x+dp[i+1][(int)b.size()];
        }
        for(int i=(int)a.size()-1;i>=0;i--){
            for(int j=(int)b.size()-1;j>=0;j--){
                int indexc=(int)c.size()-(int)a.size()-(int)b.size()+i+j;
                int mine=INT_MAX;
                if(c[indexc]!=a[i]){
                  mine=min(mine,1+dp[i+1][j]);
                }
                else{
                    mine=min(mine,dp[i+1][j]);
                }
                if(c[indexc]!=b[j]){
                    mine=min(mine,1+dp[i][j+1]);
                }
                else{
                    mine=min(mine,dp[i][j+1]);
                }
                dp[i][j]=mine;
            }
        }
        cout<<dp[0][0]<<"\n";
    }
}