ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>



using namespace std;

int t, s, x, dv, th;

string n;

int main()

{   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> t;

    while (t--) {

        cin >> n;

        dv = 0; th = 0; x = 0; s = 0;

        for (int i = 0; i < n.size(); i++) {

            x = n[i] - '0';

            s += x;

            if (x == 2) {dv++;}

            if (x == 3) {th++;}

        }

        if (s % 9 == 0) {cout << "YES" << '\n'; continue;}

        int f = 0;

        while (s % 9 != 0) {

            if (dv == 0 && th == 0) {break;}

            if (dv > 0) {s += 2; dv--;}

            if (s % 9 == 0) {f = 1; break;}

            if (th > 0) {s += 6; th--;}

            if (s % 9 == 0) {f = 1; break;}

            if (s % 9 == 2) {f = 1; break;}

        }

        if (f == 0) {cout << "NO" << '\n';} else {cout << "YES" << '\n';}

    }

    return 0;

}



Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>



using namespace std;

int t, s, x, dv, th;

string n;

int main()

{   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> t;

    while (t--) {

        cin >> n;

        dv = 0; th = 0; x = 0; s = 0;

        for (int i = 0; i < n.size(); i++) {

            x = n[i] - '0';

            s += x;

            if (x == 2) {dv++;}

            if (x == 3) {th++;}

        }

        if (s % 9 == 0) {cout << "YES" << '\n'; continue;}

        int f = 0;

        while (s % 9 != 0) {

            if (dv == 0 && th == 0) {break;}

            if (dv > 0) {s += 2; dv--;}

            if (s % 9 == 0) {f = 1; break;}

            if (th > 0) {s += 6; th--;}

            if (s % 9 == 0) {f = 1; break;}

            //if (s % 9 == 2) {f = 1; break;}

        }

        if (f == 0) {cout << "NO" << '\n';} else {cout << "YES" << '\n';}

    }

    return 0;

}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		int a[n + 2]={};
		int sum[n + 2]={};
		int sum1[n  + 2]={};
		int sum2[n  + 2]={};
		for (int j = 0; j < n; j++) {
			cin >> a[j];
		}
		sum[0] = a[0];
		sum1[0] = a[0];
		sum2[1] = a[1];
		for (int j = 1; j < n; j++) {
			sum[j] += sum[j - 1] + a[j];
			cout<<sum[j]<<"  "<<1<<"\n";
		}
		for (int j = 1; j < n; j += 2) {
			sum1[j + 1] += sum1[j - 1] + a[j + 1];
			cout<<sum1[j+1]<<"  "<<2<<"\n";
		}
		for (int j = 1; j < n; j += 2) {
			sum2[j + 2] += sum2[j] + a[j + 2];
			cout<<sum2[j+2]<<"  "<<3<<"\n";
		}
		if (n % 2 == 0) {
if (sum[n-1]%n==0&&sum1[n-2]%(n/2)==0&&sum2[n-1]%(n/2)==0&&sum[n-1]/n==sum1[n-2]/(n/2)&&sum[n-1]/n==sum2[n-1]/(n/2)){
				cout<<"Yes"<<"\n";
			}
			else cout<<"No"<<"\n";
			} 
	
		else {
if (sum[n-1]%n==0&&sum1[n-1]%(n/2+1)==0&&sum2[n-2]%(n/2)==0&&sum[n-1]/n==sum1[n-1]/(n/2+1)&&sum[n-1]/n==sum2[n-2]/(n/2)){
				cout<<"Yes"<<"\n";
			}
			else cout<<"No"<<"\n";
			}
	}

}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
/* 
Welcome to JDoodle!

You can execute code here in 88 languages. Right now you’re in the C++ IDE.

  1. Click the orange Execute button ▶ to execute the sample code below and see how it works.

  2. Want help writing or debugging code? Type a query into JDroid on the right hand side ---------------->

  3. Try the menu buttons on the left. Save your file, share code with friends and open saved projects.

Want to change languages? Try the search bar up the top. 
*/

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int tc; cin>>tc;
    while(tc--){
        ll n; cin>>n;
        ll arr[n];
        ll sum=0;
        for(int i=0;i<n;i++){
            cin>>arr[i];
            sum += arr[i];
        }
        if(sum%n !=0 ){
            cout<<"NO"<<endl;
            continue;
        }
        ll val = sum/n;
        int f=0;
        for(int i=1;i<n-1;i++){
            
            ll diff = abs(val-arr[i-1]);
            if(arr[i-1]>=val){
                arr[i-1] = val;
                arr[i+1] += diff;
            }else{
                arr[i-1] = val;
                if(arr[i+1] - diff <=0){
                    cout<<"NO"<<endl;
                    f=1;
                    break;
                }
                arr[i+1] -= diff;
            }
        }
        if(f==1){
            continue;
        }
        for(int i=0;i<n;i++){
            if(arr[i]!=val){
                cout<<"NO"<<endl;
                f=1;
                break;
            }
        }
        if(f==0){
            cout<<"YES"<<endl;
        }
    }
}













Submission (verdict: Accepted):
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
int n;
const int maxn=2e5+5;
int a[maxn];
signed main(){
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        int ans=0,sum=0;
        for(int i=1;i<=n;i+=2)
            ans+=a[i];
        for(int i=2;i<=n;i+=2)
            sum+=a[i];
        if(n%2==0){
            if(ans%(n/2)!=0||sum%(n/2)!=0) cout<<"NO"<<endl;
            else{
                if(ans==sum) cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
        }else{
            if(ans%(n/2+1)!=0||sum%(n/2)!=0) cout<<"NO"<<endl;
            else{
                if(ans/(n/2+1)==sum/(n/2)) cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
        }
    } 
    return 0;
}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		int a[n + 2]={};
		int sum[n + 2]={};
		int sum1[n  + 2]={};
		int sum2[n  + 2]={};
		for (int j = 0; j < n; j++) {
			cin >> a[j];
		}
		sum[0] = a[0];
		sum1[0] = a[0];
		sum2[1] = a[1];
		for (int j = 1; j < n; j++) {
			sum[j] += sum[j - 1] + a[j];
			cout<<sum[j]<<"  "<<1<<"\n";
		}
		for (int j = 1; j < n; j += 2) {
			sum1[j + 1] += sum1[j - 1] + a[j + 1];
			cout<<sum1[j+1]<<"  "<<2<<"\n";
		}
		for (int j = 1; j < n; j += 2) {
			sum2[j + 2] += sum2[j] + a[j + 2];
			cout<<sum2[j+2]<<"  "<<3<<"\n";
		}
		if (n % 2 == 0) {
if (sum[n-1]%n==0&&sum1[n-2]%(n/2)==0&&sum2[n-1]%(n/2)==0&&sum[n-1]/n==sum1[n-2]/(n/2)&&sum[n-1]/n==sum2[n-1]/(n/2)){
				cout<<"Yes"<<"\n";
			}
			else cout<<"No"<<"\n";
			} 
	
		else {
if (sum[n-1]%n==0&&sum1[n-1]%(n/2+1)==0&&sum2[n-2]%(n/2)==0&&sum[n-1]/n==sum1[n-1]/(n/2+1)&&sum[n-1]/n==sum2[n-2]/(n/2)){
				cout<<"Yes"<<"\n";
			}
			else cout<<"No"<<"\n";
			}
	}

}

Submission (verdict: Wrong answer on test 2):
/* 
Welcome to JDoodle!

You can execute code here in 88 languages. Right now you’re in the C++ IDE.

  1. Click the orange Execute button ▶ to execute the sample code below and see how it works.

  2. Want help writing or debugging code? Type a query into JDroid on the right hand side ---------------->

  3. Try the menu buttons on the left. Save your file, share code with friends and open saved projects.

Want to change languages? Try the search bar up the top. 
*/

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int tc; cin>>tc;
    while(tc--){
        ll n; cin>>n;
        ll arr[n];
        ll sum=0;
        for(int i=0;i<n;i++){
            cin>>arr[i];
            sum += arr[i];
        }
        if(sum%n !=0 ){
            cout<<"NO"<<endl;
            continue;
        }
        ll val = sum/n;
        int f=0;
        for(int i=1;i<n-1;i++){
            
            ll diff = abs(val-arr[i-1]);
            if(arr[i-1]>=val){
                arr[i-1] = val;
                arr[i+1] += diff;
            }else{
                arr[i-1] = val;
                if(arr[i+1] - diff <=0){
                    cout<<"NO"<<endl;
                    f=1;
                    break;
                }
                arr[i+1] -= diff;
            }
        }
        if(f==1){
            continue;
        }
        for(int i=0;i<n;i++){
            if(arr[i]!=val){
                cout<<"NO"<<endl;
                f=1;
                break;
            }
        }
        if(f==0){
            cout<<"YES"<<endl;
        }
    }
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int rec(int i, int j,int k,  string &a,string &b,string &c){
    
 
    if (i+j>=c.size())
    {
        return 0;
    }

        int take1=1e9;
        int take2=1e9;
        if (i<a.size())
        {
            take1=rec(i+1,j,i+j+1,a,b,c);
            if( a[i]!=c[i+j])
              {
                take1++;
              }
        }
        if (j<b.size())
        {
            take2=rec(i,j+1,i+j+1,a,b,c);
            if( b[j]!=c[i+j])
              {
                take2++;
              }
        }
        
         return min(take1,take2);
}

int main() {
    // Write C++ code here
  int t;
  cin>>t;
  while(t--)
  {

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

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

Submission (verdict: Accepted):
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int rec(int i, int j,  string &a,string &b,string &c, vector<vector<int>>&dp){
    
 
    if (i+j>=c.size())
    {
        return 0;
    }
    if (dp[i][j]!=-1)
    {
    return dp[i][j];
    }

        int take1=1e9;
        int take2=1e9;
        if (i<a.size())
        {
            take1=rec(i+1,j,a,b,c,dp);
            if( a[i]!=c[i+j])
              {
                take1++;
              }
        }
        if (j<b.size())
        {
            take2=rec(i,j+1,a,b,c,dp);
            if( b[j]!=c[i+j])
              {
                take2++;
              }
        }
        
         return dp[i][j]=min(take1,take2);
}

int main() {
    // Write C++ code here
  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<<rec(0,0,a,b,c,dp)<<endl;
  }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int rec(int i, int j,int k,  string &a,string &b,string &c){
    
    if (i>=a.size() and j>=b.size()){
        return 0;
    }
    if (k>=c.size())
    {
        return 1e7;
    }
    // cout<<"i "<<i<<" j "<<j<<" k "<<k<<endl;
    if (k<c.size() and i<a.size() and a[i]==c[k] )
    {
        int take1=rec(i+1,j,k+1,a,b,c);
        int take2=1e7;
        if (k<c.size() and j<b.size() and b[j]==c[k])
           take2=rec(i,j+1,k+1,a,b,c);
           return min(take1,take2);
    }else if(k<c.size() and j<b.size() and b[j]==c[k]){
        int take1=rec(i,j+1,k+1,a,b,c);;
        int take2=1e7;
         if (k<c.size() and i<a.size() and a[i]==c[k])
          take2=rec(i+1,j,k+1,a,b,c);
             return min(take1,take2);
    }
        return 1+min(rec(i+1,j,k+1,a,b,c), rec(i,j+1,k+1,a,b,c));
}

int main() {
    // Write C++ code here
  int t;
  cin>>t;
  while(t--)
  {
      string a,b,c;
      cin>>a>>b>>c;
   cout<<rec(0,0,0,a,b,c)<<endl;
  }
    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int rec(int i, int j,int k,  string &a,string &b,string &c){
    
 
    if (i+j>=c.size())
    {
        return 0;
    }

        int take1=1e9;
        int take2=1e9;
        if (i<a.size())
        {
            take1=rec(i+1,j,i+j+1,a,b,c);
            if( a[i]!=c[i+j])
              {
                take1++;
              }
        }
        if (j<b.size())
        {
            take2=rec(i,j+1,i+j+1,a,b,c);
            if( b[j]!=c[i+j])
              {
                take2++;
              }
        }
        
         return min(take1,take2);
}

int main() {
    // Write C++ code here
  int t;
  cin>>t;
  while(t--)
  {

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

   cout<<rec(0,0,0,a,b,c)<<endl;
  }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int rec(int i, int j,int k,  string &a,string &b,string &c){
    
    if (i>=a.size() and j>=b.size()){
        return 0;
    }
    if (k>=c.size())
    {
        return 1e7;
    }
    // cout<<"i "<<i<<" j "<<j<<" k "<<k<<endl;
    if (k<c.size() and i<a.size() and a[i]==c[k] )
    {
        int take1=rec(i+1,j,k+1,a,b,c);
        int take2=1e7;
        if (k<c.size() and j<b.size() and b[j]==c[k])
           take2=rec(i,j+1,k+1,a,b,c);
           return min(take1,take2);
    }else if(k<c.size() and j<b.size() and b[j]==c[k]){
        int take1=rec(i,j+1,k+1,a,b,c);;
        int take2=1e7;
         if (k<c.size() and i<a.size() and a[i]==c[k])
          take2=rec(i+1,j,k+1,a,b,c);
             return min(take1,take2);
    }
        return 1+min(rec(i+1,j,k+1,a,b,c), rec(i,j+1,k+1,a,b,c));
}

int main() {
    // Write C++ code here
  int t;
  cin>>t;
  while(t--)
  {
      string a,b,c;
      cin>>a>>b>>c;
   cout<<rec(0,0,0,a,b,c)<<endl;
  }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int rec(string a,string b,string c,int i,int j,int n1,int n2){
    if(i==n1 && j==n2){
        return 0;
    }
    if(i==n1){
        if(b[j]==c[i+j]){
            return rec(a,b,c,i,j+1,n1,n2);
        }
        else 
        return 1+rec(a,b,c,i,j+1,n1,n2);
    }
    if(j==n2){
        if(a[i]==c[i+j]){
            return rec(a,b,c,i+1,j,n1,n2);
        }
        else 
        return 1+rec(a,b,c,i+1,j,n1,n2);
    }
    if(a[i]==c[i+j] && b[j]==c[i+j]){
        return min(rec(a,b,c,i+1,j,n1,n2),rec(a,b,c,i,j+1,n1,n2));
    }
    else if(a[i]==c[i+j]){
        return min(1+rec(a,b,c,i,j+1,n1,n2),rec(a,b,c,i+1,j,n1,n2));
    }
    else if(b[j]==c[i+j]){
        return min(1+rec(a,b,c,i+1,j,n1,n2),rec(a,b,c,i,j+1,n1,n2));
    }
    else{
        return 1+min(rec(a,b,c,i+1,j,n1,n2),rec(a,b,c,i,j+1,n1,n2));
    }
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n1=a.size(),n2=b.size();
    cout<<rec(a,b,c,0,0,n1,n2)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int rec(string a,string b,string c,int i,int j,int n1,int n2,vector<vector<int>> &dp){
   if(dp[i][j]!=-1)
       return dp[i][j];
    if(i==n1 && j==n2){
        return 0;
    }
    if(i==n1){
        if(b[j]==c[i+j]){
            return rec(a,b,c,i,j+1,n1,n2,dp);
        }
        else 
        return 1+rec(a,b,c,i,j+1,n1,n2,dp);
    }
    if(j==n2){
        if(a[i]==c[i+j]){
            return rec(a,b,c,i+1,j,n1,n2,dp);
        }
        else 
        return 1+rec(a,b,c,i+1,j,n1,n2,dp);
    }
    if(a[i]==c[i+j] && b[j]==c[i+j]){
        return min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else if(a[i]==c[i+j]){
        return min(1+rec(a,b,c,i,j+1,n1,n2,dp),rec(a,b,c,i+1,j,n1,n2,dp));
    }
    else if(b[j]==c[i+j]){
        return min(1+rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else{
        return 1+min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n1=a.size(),n2=b.size();
    vector<vector<int>> dp(n1+1,vector<int>(n2+1,-1));
    cout<<rec(a,b,c,0,0,n1,n2,dp)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int rec(string a,string b,string c,int i,int j,int n1,int n2,vector<vector<int>> &dp){
   if(dp[i][j]!=-1)
       return dp[i][j];
    if(i==n1 && j==n2){
        return 0;
    }
    if(i==n1){
        if(b[j]==c[i+j]){
            return rec(a,b,c,i,j+1,n1,n2,dp);
        }
        else 
        return 1+rec(a,b,c,i,j+1,n1,n2,dp);
    }
    if(j==n2){
        if(a[i]==c[i+j]){
            return rec(a,b,c,i+1,j,n1,n2,dp);
        }
        else 
        return 1+rec(a,b,c,i+1,j,n1,n2,dp);
    }
    if(a[i]==c[i+j] && b[j]==c[i+j]){
        return min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else if(a[i]==c[i+j]){
        return min(1+rec(a,b,c,i,j+1,n1,n2,dp),rec(a,b,c,i+1,j,n1,n2,dp));
    }
    else if(b[j]==c[i+j]){
        return min(1+rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else{
        return 1+min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n1=a.size(),n2=b.size();
    vector<vector<int>> dp(n1+1,vector<int>(n2+1,-1));
    cout<<rec(a,b,c,0,0,n1,n2,dp)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int rec(string a,string b,string c,int i,int j,int n1,int n2,vector<vector<int>> &dp){
   if(dp[i][j]!=-1)
       return dp[i][j];
    if(i==n1 && j==n2){
        return dp[i][j]=0;
    }
    if(i==n1){
        if(b[j]==c[i+j]){
            return dp[i][j]=rec(a,b,c,i,j+1,n1,n2,dp);
        }
        else 
        return dp[i][j]=1+rec(a,b,c,i,j+1,n1,n2,dp);
    }
    if(j==n2){
        if(a[i]==c[i+j]){
            return dp[i][j]=rec(a,b,c,i+1,j,n1,n2,dp);
        }
        else 
        return dp[i][j]=1+rec(a,b,c,i+1,j,n1,n2,dp);
    }
    if(a[i]==c[i+j] && b[j]==c[i+j]){
        return dp[i][j]=min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else if(a[i]==c[i+j]){
        return dp[i][j]=min(1+rec(a,b,c,i,j+1,n1,n2,dp),rec(a,b,c,i+1,j,n1,n2,dp));
    }
    else if(b[j]==c[i+j]){
        return dp[i][j]=min(1+rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else{
        return dp[i][j]=1+min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n1=a.size(),n2=b.size();
    vector<vector<int>> dp(n1+1,vector<int>(n2+1,-1));
    cout<<rec(a,b,c,0,0,n1,n2,dp)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int rec(string a,string b,string c,int i,int j,int n1,int n2,vector<vector<int>> &dp){
   if(dp[i][j]!=-1)
       return dp[i][j];
    if(i==n1 && j==n2){
        return dp[i][j]=0;
    }
    if(i==n1){
        if(b[j]==c[i+j]){
            return dp[i][j]=rec(a,b,c,i,j+1,n1,n2,dp);
        }
        else 
        return dp[i][j]=1+rec(a,b,c,i,j+1,n1,n2,dp);
    }
    if(j==n2){
        if(a[i]==c[i+j]){
            return dp[i][j]=rec(a,b,c,i+1,j,n1,n2,dp);
        }
        else 
        return dp[i][j]=1+rec(a,b,c,i+1,j,n1,n2,dp);
    }
    if(a[i]==c[i+j] && b[j]==c[i+j]){
        return dp[i][j]=min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else if(a[i]==c[i+j]){
        return dp[i][j]=min(1+rec(a,b,c,i,j+1,n1,n2,dp),rec(a,b,c,i+1,j,n1,n2,dp));
    }
    else if(b[j]==c[i+j]){
        return dp[i][j]=min(1+rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else{
        return dp[i][j]=1+min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n1=a.size(),n2=b.size();
    vector<vector<int>> dp(n1+1,vector<int>(n2+1,-1));
    cout<<rec(a,b,c,0,0,n1,n2,dp)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int rec(vector<char>& a,vector<char>& b,vector<char>&  c,int i,int j,int n1,int n2,vector<vector<int>> &dp){
   if(dp[i][j]!=-1)
       return dp[i][j];
    if(i==n1 && j==n2){
        return dp[i][j]=0;
    }
    if(i==n1){
        if(b[j]==c[i+j]){
            return dp[i][j]=rec(a,b,c,i,j+1,n1,n2,dp);
        }
        else 
        return dp[i][j]=1+rec(a,b,c,i,j+1,n1,n2,dp);
    }
    if(j==n2){
        if(a[i]==c[i+j]){
            return dp[i][j]=rec(a,b,c,i+1,j,n1,n2,dp);
        }
        else 
        return dp[i][j]=1+rec(a,b,c,i+1,j,n1,n2,dp);
    }
    if(a[i]==c[i+j] && b[j]==c[i+j]){
        return dp[i][j]=min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else if(a[i]==c[i+j]){
        return dp[i][j]=min(1+rec(a,b,c,i,j+1,n1,n2,dp),rec(a,b,c,i+1,j,n1,n2,dp));
    }
    else if(b[j]==c[i+j]){
        return dp[i][j]=min(1+rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
    else{
        return dp[i][j]=1+min(rec(a,b,c,i+1,j,n1,n2,dp),rec(a,b,c,i,j+1,n1,n2,dp));
    }
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n1=a.size(),n2=b.size();
    vector<char>a1(n1),b1(n2),c1(n1+n2);
    for(int i=0;i<n1;i++){
        a1[i]=a[i];
    }
    for(int i=0;i<n2;i++){
        b1[i]=b[i];
    }
    for(int i=0;i<n1+n2;i++){
        c1[i]=c[i];
    }
    vector<vector<int>> dp(n1+1,vector<int>(n2+1,-1));
    cout<<rec(a1,b1,c1,0,0,n1,n2,dp)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int rec(string a,string b,string c,int i,int j,int n1,int n2){
    if(i==n1 && j==n2){
        return 0;
    }
    if(i==n1){
        if(b[j]==c[i+j]){
            return rec(a,b,c,i,j+1,n1,n2);
        }
        else 
        return 1+rec(a,b,c,i,j+1,n1,n2);
    }
    if(j==n2){
        if(a[i]==c[i+j]){
            return rec(a,b,c,i+1,j,n1,n2);
        }
        else 
        return 1+rec(a,b,c,i+1,j,n1,n2);
    }
    if(a[i]==c[i+j] && b[j]==c[i+j]){
        return min(rec(a,b,c,i+1,j,n1,n2),rec(a,b,c,i,j+1,n1,n2));
    }
    else if(a[i]==c[i+j]){
        return min(1+rec(a,b,c,i,j+1,n1,n2),rec(a,b,c,i+1,j,n1,n2));
    }
    else if(b[j]==c[i+j]){
        return min(1+rec(a,b,c,i+1,j,n1,n2),rec(a,b,c,i,j+1,n1,n2));
    }
    else{
        return 1+min(rec(a,b,c,i+1,j,n1,n2),rec(a,b,c,i,j+1,n1,n2));
    }
}
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n1=a.size(),n2=b.size();
    cout<<rec(a,b,c,0,0,n1,n2)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}