Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<climits>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<queue>
#define ll long long int
using namespace std;

int solve(string a,string b,string c,int i,int j,int s,vector<vector<vector<int> > >&dp){
    if(i==a.size() && j==b.size()){
        if(s==1){
            if(a[i-1]!=c[i+j+1-2]){
                return dp[i][j][s]=1;
            }
            return  dp[i][j][s]=0;
        }
        if(b[j-1]!=c[i+j+1-2]){
            return  dp[i][j][s]=1;
        }
        return  dp[i][j][s]=0;
        
    }
    if(dp[i][j][s]!=-1){
        return dp[i][j][s];
    }
    if(s==1){
        int cmp=i+j+1-2;
        int add=0;
        if(a[i-1]!=c[cmp]){
            add=1;
        }
        int c1=1e9,c2=1e9;
        if(i+1<=a.size()-1+1){
            c1=add+solve(a,b,c,i+1,j,1,dp);
        }

        if(j+1<=b.size()-1+1){
            c2=add+solve(a,b,c,i,j+1,0,dp);
        }

        return  dp[i][j][s]=min(c1,c2);

        }
        int cmp=i+j+1-2;
        int add=0;
        if(b[j-1]!=c[cmp]){
            add=1;
        }
        int c1=1e9,c2=1e9;
        if(i+1<=a.size()-1+1){
            c1=add+solve(a,b,c,i+1,j,1,dp);
        }

        if(j+1<=b.size()-1+1){
            c2=add+solve(a,b,c,i,j+1,0,dp);
        }

        return  dp[i][j][s]=min(c1,c2);


    





}
int solve2(string a,string b,string c){
    int n1=a.size();
    int n2=b.size();
        
    vector<vector<vector<int> > >dp(n1+1,vector<vector<int> >(n2+1,vector<int>(2,0)));

    for(int i=a.size();i>=0;i--){
        for(int j=b.size();j>=0;j--){
            for(int s=0;s<=1;s++){
                if(i==a.size() && j==b.size()){
        if(s==1){
            if(a[i-1]!=c[i+j+1-2]){
                 dp[i][j][s]=1;
            }
              dp[i][j][s]=0;
        }
        else if(b[j-1]!=c[i+j+1-2]){
           dp[i][j][s]=1;
        }
        else{
         dp[i][j][s]=0;}
         continue;
        
    }
    
    if(s==1){
        int cmp=i+j+1-2;
        int add=0;
        if(a[i-1]!=c[cmp]){
            add=1;
        }
        int c1=1e9,c2=1e9;
        if(i+1<=a.size()-1+1){
            c1=add+dp[i+1][j][1];
        }

        if(j+1<=b.size()-1+1){
            c2=add+dp[i][j+1][0];
        }

         dp[i][j][s]=min(c1,c2);

        }

        else{
        int cmp=i+j+1-2;
        int add=0;
        if(b[j-1]!=c[cmp]){
            add=1;
        }
        int c1=1e9,c2=1e9;
        if(i+1<=a.size()-1+1){
            c1=add+dp[i+1][j][1];
        }

        if(j+1<=b.size()-1+1){
            c2=add+dp[i][j+1][0];
        }

         dp[i][j][s]=min(c1,c2);
        }








            }
        }
    }

    return dp[1][0][1];
    



}

int main(){
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int t=1;
     cin>>t;
     while(t--){
        string a;
        cin>>a;

        string b;
        cin>>b;

        string c;
        cin>>c;
        int n1=a.size();
        int n2=b.size();
        
       // vector<vector<vector<int> > >dp1(n1+1,vector<vector<int> >(n2+1,vector<int>(2,-1)));
        // vector<vector<vector<int> > >dp2(n1+1,vector<vector<int> >(n2+1,vector<int>(2,-1)));

        int ans1=solve2(a,b,c);
        //int ans2=solve(a,b,c,0,1,0,dp2);

        cout<<ans1<<endl;


      
     
       
       
       
        




        
     }


}

Submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<climits>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<queue>
#define ll long long int
using namespace std;

int solve2(string a,string b,string c){
    int n1=a.size();
    int n2=b.size();
        
    vector<vector<vector<int> > >dp(n1+1,vector<vector<int> >(n2+1,vector<int>(2,0)));

    for(int i=a.size();i>=1;i--){
        for(int j=b.size();j>=0;j--){
            for(int s=0;s<=1;s++){
                if(i==a.size() && j==b.size()){
        if(s==1){
            if(a[i-1]!=c[i+j+1-2]){
                 dp[i][j][s]=1;
            }
              dp[i][j][s]=0;
        }
        else if(b[j-1]!=c[i+j+1-2]){
           dp[i][j][s]=1;
        }
        else{
         dp[i][j][s]=0;}
         continue;
        
    }
    
    if(s==1){
        int cmp=i+j+1-2;
        int add=0;
        if(a[i-1]!=c[cmp]){
            add=1;
        }
        int c1=1e9,c2=1e9;
        if(i+1<=a.size()-1+1){
            c1=add+dp[i+1][j][1];
        }

        if(j+1<=b.size()-1+1){
            c2=add+dp[i][j+1][0];
        }

         dp[i][j][s]=min(c1,c2);

        }

        else{
        int cmp=i+j+1-2;
        int add=0;
        if(b[j-1]!=c[cmp]){
            add=1;
        }
        int c1=1e9,c2=1e9;
        if(i+1<=a.size()-1+1){
            c1=add+dp[i+1][j][1];
        }

        if(j+1<=b.size()-1+1){
            c2=add+dp[i][j+1][0];
        }

         dp[i][j][s]=min(c1,c2);
        }








            }
        }
    }

    return dp[1][0][1];
    }

int solve3(string a,string b,string c){
     int n1=a.size();
    int n2=b.size();
        
    vector<vector<vector<int> > >dp(n1+1,vector<vector<int> >(n2+1,vector<int>(2,0)));

    for(int i=a.size();i>=0;i--){
        for(int j=b.size();j>=1;j--){
            for(int s=1;s>=0;s--){
                if(i==a.size() && j==b.size()){
        if(s==1){
            if(a[i-1]!=c[i+j+1-2]){
                 dp[i][j][s]=1;
            }
              dp[i][j][s]=0;
        }
        else if(b[j-1]!=c[i+j+1-2]){
           dp[i][j][s]=1;
        }
        else{
         dp[i][j][s]=0;}
         continue;
        
    }
    
    if(s==1){
        int cmp=i+j+1-2;
        int add=0;
        if(a[i-1]!=c[cmp]){
            add=1;
        }
        int c1=1e9,c2=1e9;
        if(i+1<=a.size()-1+1){
            c1=add+dp[i+1][j][1];
        }

        if(j+1<=b.size()-1+1){
            c2=add+dp[i][j+1][0];
        }

         dp[i][j][s]=min(c1,c2);

        }

        else{
        int cmp=i+j+1-2;
        int add=0;
        if(b[j-1]!=c[cmp]){
            add=1;
        }
        int c1=1e9,c2=1e9;
        if(i+1<=a.size()-1+1){
            c1=add+dp[i+1][j][1];
        }

        if(j+1<=b.size()-1+1){
            c2=add+dp[i][j+1][0];
        }

         dp[i][j][s]=min(c1,c2);
        }








            }
        }
    }

    return dp[0][1][0];

}

int main(){
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int t=1;
     cin>>t;
     while(t--){
        string a;
        cin>>a;

        string b;
        cin>>b;

        string c;
        cin>>c;
        int n1=a.size();
        int n2=b.size();
        
       // vector<vector<vector<int> > >dp1(n1+1,vector<vector<int> >(n2+1,vector<int>(2,-1)));
        // vector<vector<vector<int> > >dp2(n1+1,vector<vector<int> >(n2+1,vector<int>(2,-1)));

        int ans1=solve2(a,b,c);
        int ans2=solve3(a,b,c);

        cout<<min(ans1,ans2)<<endl;


      
     
       
       
       
        




        
     }


}