ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e5+5
vector<vector<int>> dp;
int solve(string a,string b,string c,int ind1,int ind2){
    // base case
    // cout<<ind1<<" "<<ind2<<endl;
    if(ind1 == a.size() && ind2 == b.size()){
        return 0;
    }
    if(dp[ind1][ind2] != -1){
        return dp[ind1][ind2];
    }
    int op1 = inf;
    int op2 = inf;
    int op3 = inf;
    int op4 = inf;

    if(a[ind1] == c[ind1+ind2] && ind1<a.size()){
        op1 = solve(a,b,c,ind1+1,ind2);
    }
    if(b[ind2] == c[ind1+ind2] && ind2<b.size()){
        op2 = solve(a,b,c,ind1,ind2+1);
    }
    if(ind1<a.size())op3 = 1 + solve(a,b,c,ind1+1,ind2);
    if(ind2<b.size())op4 = 1 + solve(a,b,c,ind1,ind2+1);
    return min({op1,op2,op3,op4});
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        int k = c.size();
        dp = vector<vector<int>>(n+1,vector<int>(m+1,-1));
        dp[n][m] = 0;
        int ans = solve(a,b,c,0,0); 
        cout<<ans<<endl;
    }
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e5+5
vector<vector<int>> dp;
int solve(string a,string b,string c,int ind1,int ind2){
    // base case
    // cout<<ind1<<" "<<ind2<<endl;
    if(ind1 == a.size() && ind2 == b.size()){
        return 0;
    }
    if(dp[ind1][ind2] != -1){
        return dp[ind1][ind2];
    }
    int op1 = inf;
    int op2 = inf;
    int op3 = inf;
    int op4 = inf;

    if(a[ind1] == c[ind1+ind2] && ind1<a.size()){
        op1 = solve(a,b,c,ind1+1,ind2);
    }
    if(b[ind2] == c[ind1+ind2] && ind2<b.size()){
        op2 = solve(a,b,c,ind1,ind2+1);
    }
    if(ind1<a.size())op3 = 1 + solve(a,b,c,ind1+1,ind2);
    if(ind2<b.size())op4 = 1 + solve(a,b,c,ind1,ind2+1);
    return dp[ind1][ind2] = min({op1,op2,op3,op4});
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        int k = c.size();
        dp = vector<vector<int>>(n+1,vector<int>(m+1,-1));
        dp[n][m] = 0;
        // int ans = solve(a,b,c,0,0); 
        for(int i=(n);i>=0;i--){
            for(int j=(m);j>=0;j--){
                if(i==n && j==m) continue;
                int op1 = inf;
                int op2 = inf;
                int op3 = inf;
                int op4 = inf;
                if(i<n && a[i] == c[i+j]){
                    op1 = dp[i+1][j];
                }
                if(j<m && b[j] == c[i+j]){
                    op2 = dp[i][j+1];
                }
                if(i<n)op3 = 1 + dp[i+1][j];
                if(j<m)op4 = 1 + dp[i][j+1];
                dp[i][j] = min(op1,min(op2,min(op3,op4)));
            }
        }
        cout<<dp[0][0]<<endl;
        // cout<<ans<<endl;
    }
}

Answer: 2
Problem: 2050E - Three Strings
Language: c++23 

Code 1:
#include<bits/stdc++.h>
using namespace std;
int dp[1010][1010];
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.size(),m=b.size();
        a=" "+a,b=" "+b,c=" "+c;
        for(int i=1;i<=n+2;i++)
            for(int j=1;j<=m+2;j++)
                dp[i][j]=1e9;
        for(int i=1;i<=n;i++)
            dp[i][0]=dp[i-1][0]+(a[i]!=c[i]);
        for(int i=1;i<=m;i++)
            dp[0][i]=dp[0][i-1]+(b[i]!=c[i]);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                dp[i][j]=min(dp[i-1][j]+(a[i]!=c[i+j]),dp[i][j-1]+(b[j]==c[i+j]));
        cout<<dp[n][m]<<"\n";
    }
}


Code 2:
#include<bits/stdc++.h>
using namespace std;
int dp[1010][1010];
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.size(),m=b.size();
        //a=" "+a,b=" "+b,c=" "+c;
        for(int i=0;i<=n;i++)
            for(int j=0;j<=m;j++)
                dp[i][j]=1e9;
        dp[0][0]=0;
        for(int i=0;i<n;i++)
            dp[i+1][0]=dp[i][0]+(a[i]!=c[i]);
        for(int i=0;i<m;i++)
            dp[0][i+1]=dp[0][i]+(b[i]!=c[i]);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                dp[i][j]=min(dp[i-1][j]+(a[i-1]!=c[i+j-1]),dp[i][j-1]+(b[j-1]!=c[i+j-1]));
        cout<<dp[n][m]<<"\n";
    }
}


Answer: 2
Problem: 2050E - Three Strings
Language: c++20 

Code 1:
#include <bits/stdc++.h>

using namespace std;

 

typedef long long ll;

#define vi vector <int> 

#define vll vector <ll> 

#define vp vector<pair<ll,ll>>

#define all(a) (a).begin(),(a).end()

#define rep(i,a) for(int i=0;i<a;i++)

#define fa(v) for (auto &it : (v))

#define ff first

#define ss second

#define pb push_back

#define pl pair<ll ,ll> 

 



int main() { ios::sync_with_stdio(0);cin.tie(0);

int t; cin>>t;

while (t--){ 



    string a,b,c; cin>>a>>b>>c;

    int n =a.size(), m = b.size() ;

    vector<vector<int>> dp(n+1, vector<int>(m+1,0)) ;



    dp[n][m]=0;



    for(int i=n-1;i>=0;i--){

        if(a[i]==c[m+i])dp[i][m]=dp[i+1][m];

        else {

            dp[i][m]=dp[i+1][m]+1;

        }

    }



    for(int i=m-1;i>=0;i--){

        if(b[i]==c[n+i])dp[n][i]=dp[n][i+1];

        else{

            dp[n][i]= dp[n][i+1]+1;

        }

    }



    for(int i=n-1;i>=0;i--){

        for(int j=m-1;j>=0;j--){



            int x= 1e5,y = 1e5;

            

            if(a[i]==c[i+j])x=dp[i+1][j];

            else{x= dp[i+1][j]+1 ;}



            if(b[j]==c[i+j])y=dp[i][j+1];

            else {y= dp[i][j+1]+1;}



            dp[i][j] = min(x,y) ;



        }

    }



    cout<< dp[0][0] <<endl ;



} 

}

Code 2:
#include <bits/stdc++.h>

using namespace std;

 

typedef long long ll;

#define vi vector <int> 

#define vll vector <ll> 

#define vp vector<pair<ll,ll>>

#define all(a) (a).begin(),(a).end()

#define rep(i,a) for(int i=0;i<a;i++)

#define fa(v) for (auto &it : (v))

#define ff first

#define ss second

#define pb push_back

#define pl pair<ll ,ll> 

 

    int rec(  vector<vector<int>> &dp,  string a,string b , string c, int i, int j){

        if(i+j>=c.size())return 0 ;



        // dp[i][j] == minimun changes req after index i , j ...

        

        if( dp[i][j]!=-1)return dp[i][j] ;



            

            int x = 1e7, y = 1e7, z= 1e7, w = 1e7 ;

                

            if(i<a.size()){

                x=rec(dp,a,b,c,i+1,j)+1;

                if(c[i+j]==a[i]) z= rec(dp,a,b,c,i+1,j) ;

                z=min(x,z);

            }



            if(j<b.size()){y=rec(dp,a,b,c,i,j+1)+1;

                if(c[i+j]==b[j])w = rec( dp, a,b,c ,i, j+1) ;

                w= min(y,w);

            }

//cout<<x<<z<<y<<x<<endl;

            return dp[i][j]= min(z,w) ;

    



        return 0 ;

    }



int main() { ios::sync_with_stdio(0);cin.tie(0);

int t; cin>>t;

while (t--){ 



    string a,b,c; cin>>a>>b>>c;

    int n =a.size(), m = b.size() ;

    vector<vector<int>> dp(n+1, vector<int>(m+1,-1)) ;



    cout<<rec(dp, a,b,c,0,0)<<endl ;





} 

}

Answer: 1
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 2;
int dp[N][N] = { { 0 } };

string a, b, c;

int n; // length of a
int m; // length of b

int f(int i, int j) {
  if (i == 0 && j == 0) return 0;
  if (dp[i][j] != 0) return dp[i][j];
  int choose_a = INT_MAX, choose_b = INT_MAX;
  if (i > 0) choose_a = (a[i - 1] == c[i + j - 1] ? 0 : 1) + f(i - 1, j);
  if (j > 0) choose_b = (b[j - 1] == c[i + j - 1] ? 0 : 1) + f(i, j - 1);
  return dp[i][j] = min(choose_a, choose_b);
}

void solve() {
  cin >> a >> b >> c;
  n = a.length();
  m = b.length();
  memset(dp, 0, sizeof(dp));
  cout << f(n, m) << endl;
}

int main() {
  int t;
  cin >> t;
  while (t--) solve();
}


Code 2:
#include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 2;
int dp[N][N] = { { 0 } };

string a, b, c;

int n; // length of a
int m; // length of b

int f(int i, int j) {
  if (i == 0 && j == 0) return 0;
  if (dp[i][j] != 0) return dp[i][j];
  int choose_a = INT_MAX, choose_b = INT_MAX;
  if (i > 0) choose_a = (a[i - 1] == c[i + j - 1] ? 0 : 1) + f(i - 1, j);
  if (j > 0) choose_b = (b[j - 1] == c[i + j - 1] ? 0 : 1) + f(i, j - 1);
  return dp[i][j] = min(choose_a, choose_b);
}

void solve() {
  cin >> a >> b >> c;
  n = a.length();
  m = b.length();
  cout << f(n, m) << endl;
}

int main() {
  int t;
  cin >> t;
  while (t--) solve();
}


Answer: 1
Problem: 2050E - Three Strings
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define cin(a) for(auto i =0;i<=a.size()-1;i++) cin>>a[i];
#define all(a) a.begin(),a.end()
#define ll long long
#define yy cout<<"Yes"<<endl
#define nn cout<<"No"<<endl
// const int N=3e5+2;
// int tree[4*N];
// void build(vector<int> &a,int nd,int s,int e){
//   if(s==e){
//   tree[nd]=a[s];
//   return;
//   }
//  int mid=(s+e)/2;
//  build(a,2*nd,s,mid);
//  build(a,2*nd+1,mid+1,e);
//   tree[nd]=__gcd(tree[2*nd],tree[2*nd+1]);
// }
// int qur(int nd,int s,int e,int l,int r){
//   //non-overlap interval
//   if(l>r){
//     return 0;
//   }
//   if(s>r||e<l){
//     return -1;
//   }
//   if(l<=s&&e<=r){
//     return tree[nd];
//   }
//     int mid=(s+e)/2;
//  int q1=qur(2*nd,s,mid,l,r);
//  int q2=qur(2*nd+1,mid+1,e,l,r);
// return __gcd(q1,q2);
// }
void solve(){
string a,b,c;
cin>>a;
cin>>b;
cin>>c;
vector<vector<ll>> dp(a.size()+1,vector<ll> (b.size()+1,LONG_LONG_MAX));
dp[0][0]=0;
for(int i=1;i<=c.size();i++){
  for(int j=0;j<=i;j++){
    if(j>a.size()||i-j>b.size()){
      continue;
    }
    if(j>0){      
    dp[j][i-j]=min(dp[j][i-j],dp[j-1][i-j]+(c[i-1]!=a[j-1]));
    }
    if(i-j>0){
      dp[j][i-j]=min(dp[j][i-j],dp[j][i-j-1]+(c[i-1]!=b[i-j-1]));
    }
}}
cout<<dp[a.size()][b.size()]<<endl;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
int t;
cin>>t;
while(t--){ 
    solve();
}}

Code 2:
#include<bits/stdc++.h> 
using namespace std; 
#define cin(a) for(auto i =0;i<=a.size()-1;i++) cin>>a[i]; 
#define all(a) a.begin(),a.end() 
#define ll long long 
#define yy cout<<"Yes"<<endl 
#define nn cout<<"No"<<endl 
// const int N=3e5+2; 
// int tree[4*N]; 
// void build(vector<int> &a,int nd,int s,int e){ 
// if(s==e){ 
// tree[nd]=a[s]; 
// return; 
// } 
// int mid=(s+e)/2; 
// build(a,2*nd,s,mid); 
// build(a,2*nd+1,mid+1,e); 
// tree[nd]=__gcd(tree[2*nd],tree[2*nd+1]); 
// } 
// int qur(int nd,int s,int e,int l,int r){ 
// //non-overlap interval 
// if(l>r){ 
// return 0; 
// } 
// if(s>r||e<l){ 
// return -1; 
// } 
// if(l<=s&&e<=r){ 
// return tree[nd]; 
// } 
// int mid=(s+e)/2;
// int q1=qur(2*nd,s,mid,l,r); 
// int q2=qur(2*nd+1,mid+1,e,l,r); 
// return __gcd(q1,q2); 
// } 
void solve(){ 
string a,b,c; 
cin>>a; 
cin>>b; 
cin>>c; 
vector<vector<ll>> dp(a.size()+1,vector<ll> (b.size()+1,LONG_LONG_MAX)); 
dp[0][0]=0; 
for(int i=1;i<=c.size();i++){ 
 for(int j=0;j<=i;j++){ 
 if(j>a.size()||i-j>b.size()){ 
 continue; 
 } 
 if(j>0){ 
 dp[j][i-j]=min(dp[j][i-j],dp[j-1][i-j]+(c[i-1]!=a[j-1])); 
 } 
 if(i-j>0){ 
 dp[j][i-j]=min(dp[j][i-j],dp[j][i-j-1]+(c[i-1]!=b[i-j-1])); 
 } 
}} 
cout<<dp[a.size()][b.size()]<<endl; 
} 
int main(){ 
 ios_base::sync_with_stdio(false); 
 cin.tie(0); 
 cout.tie(0); 
int t; 
cin>>t
while(t--){ 
 solve(); 
}}

Answer: 1
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define x first
#define y second

const int N = 2e3 + 10;

int qmi(int a, int k, int p)  // 求a^k mod p
{
    int res = 1 % p;
    while (k)
    {
        if (k & 1) res = (LL)res * a % p;
        a = (LL)a * a % p;
        k >>= 1;
    }
    return res;
} 

int n, k;
char s1[N], s2[N], t[N];
int f[N][N];

void solve()
{
    cin >> s1 + 1 >> s2 + 1 >> t + 1;
    int l1 = strlen(s1 + 1), l2 = strlen(s2 + 1);
    // memset(f, 0x3f, sizeof f);
    // for(int i = 0; i <= l1; i ++) f[i][0] = 0;
    // for(int j = 0; j <= l2; j ++) f[0][j] = 0;
    
    for(int i = 0; i <= l1; i ++)
        for(int j = 0; j <= l2; j ++)
        {
            if(i == 0 && j == 0) continue;
            if(i != 0) 
                f[i][j] = f[i - 1][j] + (s1[i] == t[i + j]);
            if(j != 0)
                f[i][j] = max(f[i][j], f[i][j - 1] + (s2[j] == t[i + j]));
        }
    cout << l1 + l2 - f[l1][l2] << endl;
}

int main()
{
    int t;
    cin >> t;
    while(t --)
        solve();
}

Code 2:
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define x first
#define y second

const int N = 2e3 + 10;

int qmi(int a, int k, int p)  // 求a^k mod p
{
    int res = 1 % p;
    while (k)
    {
        if (k & 1) res = (LL)res * a % p;
        a = (LL)a * a % p;
        k >>= 1;
    }
    return res;
} 

int n, k;
char s1[N], s2[N], t[N];
int f[N][N];

void solve()
{
    cin >> s1 + 1 >> s2 + 1 >> t + 1;
    int l1 = strlen(s1 + 1), l2 = strlen(s2 + 1);
    // memset(f, 0x3f, sizeof f);
    // for(int i = 0; i <= l1; i ++) f[i][0] = 0;
    // for(int j = 0; j <= l2; j ++) f[0][j] = 0;
    
    for(int i = 0; i <= l1; i ++)
        for(int j = 0; j <= l2; j ++)
        {
            f[i][j] = 0;
            if(i == 0 && j == 0) continue;
            if(i != 0) 
                f[i][j] = f[i - 1][j] + (s1[i] == t[i + j]);
            if(j != 0)
                f[i][j] = max(f[i][j], f[i][j - 1] + (s2[j] == t[i + j]));
        }
    cout << l1 + l2 - f[l1][l2] << endl;
}

int main()
{
    int t;
    cin >> t;
    while(t --)
        solve();
}

Answer: 2
Problem: 2050E - Three Strings
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define int long long

int func(string& a, string& b, string& c, int i1, int i2, int j, vector<vector<vector<int>>>& dp) {
    if (j == c.size()) return 0;

    if (dp[i1][i2][j] != -1) return dp[i1][i2][j];

    int mini = INT_MAX;
    
    if (i1 < a.size()) {
        mini = min(mini, (a[i1] != c[j]) + func(a, b, c, i1+1, i2, j+1, dp));
    }

    if (i2 < b.size()) {
        mini = min(mini, (b[i2] != c[j]) + func(a, b, c, i1, i2+1, j+1, dp));
    }

    return dp[i1][i2][j] = mini;
}

void solve() {
    string a, b, c;
    cin >> a >> b >> c;

    int n1 = a.size(), n2 = b.size(), n3 = c.size();
    vector<vector<vector<int>>> dp(n1+1, vector<vector<int>>(n2+1, vector<int>(n3+1, -1)));

    int ans = func(a, b, c, 0, 0, 0, dp);
    cout << ans << endl; 
}

int32_t main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0); 
    cout.tie(0);
    
    int t; 
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Code 2:
#include<bits/stdc++.h>
using namespace std;
#define int long long

int func(string& a, string& b, string& c, int i1, int i2, int j, vector<vector<int>>& dp) {
    if (j == c.size()) return 0;

    if (dp[i1][i2] != -1) return dp[i1][i2];

    int mini = INT_MAX;
    
    if (i1 < a.size()) {
        mini = min(mini, (a[i1] != c[j]) + func(a, b, c, i1+1, i2, j+1, dp));
    }

    if (i2 < b.size()) {
        mini = min(mini, (b[i2] != c[j]) + func(a, b, c, i1, i2+1, j+1, dp));
    }

    return dp[i1][i2] = mini;
}

void solve() {
    string a, b, c;
    cin >> a >> b >> c;

    int n1 = a.size(), n2 = b.size(), n3 = c.size();
    vector<vector<int>> dp(n1+1, vector<int>(n2+1,-1));

    int ans = func(a, b, c, 0, 0, 0, dp);
    cout << ans << endl; 
}

int32_t main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0); 
    cout.tie(0);
    
    int t; 
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Answer: 2
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
    #include "bits/stdc++.h"

    using namespace std;



    string c;



    int solve(string a, string b){

        int arr[a.length()+1][b.length()+1];

        for(int i=0; i<=a.length(); i++){

            for(int j=0; j<=b.length(); j++){

                if(i == 0 && j == 0) arr[i][j] = 0;

                else if (i == 0 && j != 0){

                    if(b[j-1] == c[j-1]) arr[i][j] = arr[i][j-1];

                    else arr[i][j] = arr[i][j-1]+1;

                } else if(i != 0 && j == 0){

                    if(a[i-1] == c[i-1]) arr[i][j] = arr[i-1][j];

                    else arr[i][j] = arr[i-1][j]+1;

                } else{

                    int ans_1, ans_2;

                    if(a[i-1] == c[i+j-1]) ans_1 = arr[i-1][j];

                    else ans_1 = arr[i-1][j]+1;

                    if(b[j-1] == c[i+j-1]) ans_2 = arr[i][j-1];

                    else ans_2 = arr[i][j-1]+1;

                    arr[i][j] = min(ans_1,ans_2);

                }

            }

        }



        return arr[a.length()][b.length()];

    }



    int main(){



        int t; cin >> t;

        while(t--){

            string a,b; cin >> a >> b >> c;

            cout << solve(a,b) << endl;

        }



        return 0;

    }

Code 2:
#include "bits/stdc++.h"

using namespace std;



int solve(string a, string b, string c){

    int arr[a.length()][b.length()];

    for(int i=0; i<a.length(); i++){

        for(int j=0; j<b.length(); j++){

            int ans_1=a.length()+b.length(), ans_2=a.length()+b.length();

            if(i != 0 and a[i] == c[i+j]) ans_1 = arr[i-1][j];

            else ans_1 = arr[i-1][j]+1;

            if(j != 0 and b[j] == c[i+j]) ans_2 = arr[i][j-1];

            else ans_2 = arr[i][j-1]+1;

            if(i != 0 and j != 0) arr[i][j] = min(ans_1,ans_2);

        }

    }

    return arr[a.length()-1][b.length()-1];

}



int main(){



    int t; cin >> t;

    while(t--){

        string a,b,c; cin >> a >> b >> c;

        cout << solve(a,b,c) << endl;

    }



    return 0;

}

Answer: 1
Problem: 2050E - Three Strings
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
using LL = long long;

void solve() {
	string a, b, c;
	cin >> a >> b >> c;
	int n = a.size(), m = b.size();
	int N = n + m;
	vector dp(N + 1, vector<int> (n + 1, 2005));
	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= min(n, i); j++) {
			if (j + 1 <= n) dp[i][j + 1] = min(dp[i][j + 1], 
				dp[i - 1][j] + (c[i - 1] != a[j]));
			dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[i - 1] != b[i - j - 1]));
		}
	}
	int ans = dp[N][n];
	cout << ans << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t;
	cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
using LL = long long;

void solve() {
	string a, b, c;
	cin >> a >> b >> c;
	int n = a.size(), m = b.size();
	int N = n + m;
	vector dp(N + 1, vector<int> (n + 1, 1005));
	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= min(n, i); j++) {
			if (j + 1 <= n) dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + (c[i - 1] != a[j]));
			dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[i - 1] != b[i - j - 1]));
		}
	}
	int ans = 1005;
	for (int i = 0; i <= n; i++) {
		ans = min(ans, dp[N][i]);
	}
	cout << ans << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t;
	cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

Answer: 1
Problem: 2050E - Three Strings
Language: c++23 

Code 1:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
map<int,int> primes;
vector<char> good={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
 
void dfs(vector<bool>&vis,char node,vector<vector<char>>&adj) {
    for(int i=0;i<adj[int(node-'a')].size();i++){
        if(!vis[adj[int(node-'a')][i]]){
            vis[adj[int(node-'a')][i]]=true;
            cout<<adj[int(node-'a')][i];
            dfs(vis,adj[int(node-'a')][i],adj);
        }
    }
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b,c;
    cin>>a>>b>>c;
    int n=a.size(),m=b.size();
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    for(int i=1;i<=n;i++){
        dp[i][0]=dp[i-1][0]+(a[i-1]!=c[i-1]);
    }
    for(int i=1;i<=m;i++){
        dp[0][i]=dp[0][i-1]+(b[i-1]!=c[i-1]);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            dp[i][j]=min((dp[i][j-1]+(b[j-1]!=c[i+j-1])),(dp[i-1][j]+(a[i-1]!=c[i+j-1])));
        }
    }
    cout<<dp[n][m]<<endl;
}

Code 2:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
map<int,int> primes;
vector<char> good={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
 
void dfs(vector<bool>&vis,char node,vector<vector<char>>&adj) {
    for(int i=0;i<adj[int(node-'a')].size();i++){
        if(!vis[adj[int(node-'a')][i]]){
            vis[adj[int(node-'a')][i]]=true;
            cout<<adj[int(node-'a')][i];
            dfs(vis,adj[int(node-'a')][i],adj);
        }
    }
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
    string a,b,c;
    cin>>a>>b>>c;
    int n=a.size(),m=b.size();
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    for(int i=1;i<=n;i++){
        dp[i][0]=dp[i-1][0]+(a[i-1]!=c[i-1]);
    }
    for(int i=1;i<=m;i++){
        dp[0][i]=dp[0][i-1]+(b[i-1]!=c[i-1]);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            dp[i][j]=min((dp[i][j-1]+(b[j-1]!=c[i+j-1])),(dp[i-1][j]+(a[i-1]!=c[i+j-1])));
        }
    }
    cout<<dp[n][m]<<endl;
    }
}

Answer: 2
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int tt;
    cin >> tt;
    while (tt--) {
        string A, B, C;
        cin >> A >> B >> C;
        int nA = int(A.size());
        int nB = int(B.size());
        vector<vector<int>> dp(nA + 1, vector<int>(nB + 1, nA + nB + 1));
        dp[0][0] = 0;
        for (int i = 0; i <= nA; i++) {
            for (int j = 0; j <= nB; j++) {
                if (i < nA) {
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (A[i] != C[i + j]));
                }
                if (j < nB) {
                    dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (B[j] != C[i + j]));
                }
            }
        }
        cout << dp[nA][nB] << endl;
    }
}

Code 2:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int tt;
    cin >> tt;
    while (tt--) {
        string a, b, c;
        cin >> a >> b >> c;

    }
}

Answer: 1
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include<bits/stdc++.h>
using namespace std;
int dp[2001][2001];
int f(string &a,string &b,string &c,int i,int j){
    if(dp[i][j]!=-1)
    return dp[i][j];
    if(i==a.length()&&j==b.length())
    return dp[i][j]=0;
    if(i>a.length()||j>b.length())
    return 1e5;
    int min_one=INT_MAX;
    if(i!=a.length()&&a[i]==c[i+j])
    min_one=min(min_one,f(a,b,c,i+1,j));
    if(j!=b.length()&&b[j]==c[i+j])
    min_one=min(min_one,f(a,b,c,i,j+1));
    min_one=min(min_one,1+min(f(a,b,c,i+1,j),f(a,b,c,i,j+1)));
    return dp[i][j]=min_one;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        for(int i=0;i<2001;i++){
            for(int j=0;j<2001;j++){
                dp[i][j]=-1;
            }
        }
        cout<<f(a,b,c,0,0)<<endl;
    }
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
int dp[1001][1001];
int f(string &a,string &b,string &c,int i,int j){
    if(dp[i][j]!=-1)
    return dp[i][j];
    if(i==a.length()&&j==b.length())
    return dp[i][j]=0;
    if(i>a.length()||j>b.length())
    return 1e5;
    int min_one=INT_MAX;
    if(i!=a.length()&&a[i]==c[i+j])
    min_one=min(min_one,f(a,b,c,i+1,j));
    if(j!=b.length()&&b[j]==c[i+j])
    min_one=min(min_one,f(a,b,c,i,j+1));
    min_one=min(min_one,1+min(f(a,b,c,i+1,j),f(a,b,c,i,j+1)));
    return dp[i][j]=min_one;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        for(int i=0;i<1001;i++){
            for(int j=0;j<1001;j++){
                dp[i][j]=-1;
            }
        }
    }
}

Answer: 1