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

Previous submission (verdict: Runtime error on test 1):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>v5;
long long power(long long A, long long B)
{
    if (B == 0)
        return 1;
 
    long long res = power(A, B / 2);
 
    if (B % 2)
        return res * res * A;
    else
        return res * res;
}
bool is_prime(int n){
   if(n==1){
       return 0;
   }
   bool b = true;
   for(int i=2;i*i<=n;i++){
       if(n%i==0){
           b = false;
           break;
       }
   }
   return b;
}
 void primeFactors(ll n)
{
     while(n%2==0){
         v5.push_back(2);
          n=(n/2);
     }
       for (int i = 3; i*i <= n; i = i+2){
            while (n%i == 0){
                  v5.push_back(i);
                n = n/i;
               }
               }
         if (n > 2){
            v5.push_back(n);
         }
}
bool cmp(pair<ll,ll> &a, pair<ll,ll> &b){
     if(a.first!=b.first){
         if(a.first>b.first) return true;
          return false;
     }
     else{
           if(a.second<b.second) return true;
           return false;
     }
}
ll factorial(ll n) 
{ 
    if (n == 0) 
        return 1; 
    return n * factorial(n - 1); 
} 
void bin(ll n)
{
    for(int i=31;i>=0;i--){
         cout<<((n>>i)&1);
    }
    cout<<endl;
    
}
ll maxSubArraySum(ll a[], ll size)
{
    ll max_so_far = LONG_LONG_MIN, max_ending_here = 0;
 
    for (int i = 0; i < size; i++) {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;
 
        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}

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

  }
        
  int main(){
ios_base::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
      string a,b,c;
      cin>>a>>b>>c;
      int n=a.size();
      int m=b.size();
      vector<vector<int>>dp(n,vector<int>(m,-1));
      cout<<f(0,0,n,m,a,b,c,dp)<<endl;




  }



  }

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>v5;
long long power(long long A, long long B)
{
    if (B == 0)
        return 1;
 
    long long res = power(A, B / 2);
 
    if (B % 2)
        return res * res * A;
    else
        return res * res;
}
bool is_prime(int n){
   if(n==1){
       return 0;
   }
   bool b = true;
   for(int i=2;i*i<=n;i++){
       if(n%i==0){
           b = false;
           break;
       }
   }
   return b;
}
 void primeFactors(ll n)
{
     while(n%2==0){
         v5.push_back(2);
          n=(n/2);
     }
       for (int i = 3; i*i <= n; i = i+2){
            while (n%i == 0){
                  v5.push_back(i);
                n = n/i;
               }
               }
         if (n > 2){
            v5.push_back(n);
         }
}
bool cmp(pair<ll,ll> &a, pair<ll,ll> &b){
     if(a.first!=b.first){
         if(a.first>b.first) return true;
          return false;
     }
     else{
           if(a.second<b.second) return true;
           return false;
     }
}
ll factorial(ll n) 
{ 
    if (n == 0) 
        return 1; 
    return n * factorial(n - 1); 
} 
void bin(ll n)
{
    for(int i=31;i>=0;i--){
         cout<<((n>>i)&1);
    }
    cout<<endl;
    
}
ll maxSubArraySum(ll a[], ll size)
{
    ll max_so_far = LONG_LONG_MIN, max_ending_here = 0;
 
    for (int i = 0; i < size; i++) {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;
 
        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}

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

  }
        
  int main(){
ios_base::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
      string a,b,c;
      cin>>a>>b>>c;
      int n=a.size();
      int m=b.size();
      vector<vector<int>>dp(n+1,vector<int>(m+1,-1));
      cout<<f(0,0,n,m,a,b,c,dp)<<endl;




  }



  }