ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
 
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
 
 
 
void init_code(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
    #endif 
}
bool cc(const pair<int, int>& a, const pair<int, int>& b) {
    if (a.first != b.first)
        return a.first < b.first;

    return a.second > b.second;
}
int main(){
	init_code();
	int t=1;
	while(t-->0){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		vector<pair<int,int>> vp;
		set<int> st;
		for(int i=0;i<n;i++){
			int num = arr[i] ;
			for(int j=arr[i]+1;j<=n;j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({j,arr[i]});
			}
			for(int j=arr[i]+1;j<=n;j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			for(int j=1;j<arr[i];j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			st.insert(arr[i]);
		}
		cout<<vp.size()<<endl;
		for(auto it:vp){
			cout<<it.first<<" "<<it.second<<endl;
		}
	}
}

Submission (verdict: Wrong answer on test 5):
#include<bits/stdc++.h>
 
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
 
 
 
void init_code(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
    #endif 
}
bool cc(const pair<int, int>& a, const pair<int, int>& b) {
    if (a.first != b.first)
        return a.first < b.first;

    return a.second > b.second;
}
int main(){
	init_code();
	int t=1;
	while(t-->0){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		vector<pair<int,int>> vp;
		set<int> st;
		for(int i=0;i<n;i++){
			int num = arr[i] ;
			for(int j=arr[i]+1;j<=n;j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({j,arr[i]});
			}
			for(int j=n;j>arr[i];j--){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			for(int j=1;j<arr[i];j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			st.insert(arr[i]);
		}
		cout<<vp.size()<<endl;
		for(auto it:vp){
			cout<<it.first<<" "<<it.second<<endl;
		}
	}
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 4):
#include<bits/stdc++.h>
 
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
 
 
 
void init_code(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
    #endif 
}
bool cc(const pair<int, int>& a, const pair<int, int>& b) {
    if (a.first != b.first)
        return a.first < b.first;

    return a.second > b.second;
}
int main(){
	init_code();
	int t=1;
	while(t-->0){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		vector<pair<int,int>> vp;
		set<int> st;
		for(int i=0;i<n;i++){
			int num = arr[i] ;
			for(int j=arr[i]+1;j<=n;j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({j,arr[i]});
			}
			for(int j=arr[i]+1;j<=n;j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			for(int j=1;j<arr[i];j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			st.insert(arr[i]);
		}
		cout<<vp.size()<<endl;
		for(auto it:vp){
			cout<<it.first<<" "<<it.second<<endl;
		}
	}
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 5):
#include<bits/stdc++.h>
 
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
 
 
 
void init_code(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
    #endif 
}
bool cc(const pair<int, int>& a, const pair<int, int>& b) {
    if (a.first != b.first)
        return a.first < b.first;

    return a.second > b.second;
}
int main(){
	init_code();
	int t=1;
	while(t-->0){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		vector<pair<int,int>> vp;
		set<int> st;
		for(int i=0;i<n;i++){
			int num = arr[i] ;
			for(int j=arr[i]+1;j<=n;j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({j,arr[i]});
			}
			for(int j=n;j>arr[i];j--){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			for(int j=1;j<arr[i];j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			st.insert(arr[i]);
		}
		cout<<vp.size()<<endl;
		for(auto it:vp){
			cout<<it.first<<" "<<it.second<<endl;
		}
	}
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
 
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long int
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
 
 
 
void init_code(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
    #endif 
}
bool cc(const pair<int, int>& a, const pair<int, int>& b) {
    if (a.first != b.first)
        return a.first < b.first;

    return a.second > b.second;
}
int main(){
	init_code();
	int t=1;
	while(t-->0){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		vector<pair<int,int>> vp;
		set<int> st;
		for(int i=0;i<n;i++){
			int num = arr[i] ;
			for(int j=arr[i]+1;j<=n;j++){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({j,arr[i]});
			}
			for(int j=n;j>arr[i];j--){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			for(int j=arr[i]-1;j>=1;j--){
				if(st.find(j)!=st.end()){
					continue;
				}
				vp.push_back({arr[i],j});
			}
			st.insert(arr[i]);
		}
		cout<<vp.size()<<endl;
		for(auto it:vp){
			cout<<it.first<<" "<<it.second<<endl;
		}
	}
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

using namespace std;

int main(){
    int tt;
    cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<long long> arr(n);
        long long sum=0;
        for(int i=0; i<n; i++){
        cin>>arr[i];
        sum+=arr[i];
        }
        int cnt=0;
        // cout<<sum<<endl;
        while(n-cnt>1){
            cnt++;
            vector<long long>brr(n-cnt,0);
            long long ans=0;
            for(int i=1; i<n-cnt+1; i++){
                brr[i-1]=(arr[i]-arr[i-1]);
            }
            sum=max(sum,abs(brr[n-cnt-1]-brr[0]));
            swap(arr,brr);
        }
        if(n-cnt==1 && n!=1)
        sum=max(sum,abs(arr[0]));
        
        cout<<sum<<endl;
    }
}

Submission (verdict: Accepted):
#include<bits/stdc++.h> 

using namespace std;

int main(){
    int tt;
    cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<long long> arr(n);
        long long sum=0;
        for(int i=0; i<n; i++){
        cin>>arr[i];
        sum+=arr[i];
        }
        int cnt=0;
        // cout<<sum<<endl;
        while(n-cnt>1){
            cnt++;
            vector<long long>brr(n-cnt,0);
            long long ans=0;
            for(int i=1; i<n-cnt+1; i++){
                brr[i-1]=(arr[i]-arr[i-1]);
            }
            sum=max(sum,abs(accumulate(brr.begin(),brr.end(),(long long)0)));
            swap(arr,brr);
        }
        
        cout<<sum<<endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

using namespace std;

int main(){
    int tt;
    cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<long long> arr(n);
        long long sum=0;
        for(int i=0; i<n; i++){
        cin>>arr[i];
        sum+=arr[i];
        }
        int cnt=0;
        // cout<<sum<<endl;
        while(n-cnt>1){
            cnt++;
            vector<long long>brr(n-cnt,0);
            long long ans=0;
            for(int i=1; i<n-cnt+1; i++){
                brr[i-1]=(arr[i]-arr[i-1]);
            }
            sum=max(sum,abs(brr[n-cnt-1]-brr[0]));
            swap(arr,brr);
        }
        if(n-cnt==1)
        sum=max(sum,abs(arr[0]));
        
        cout<<sum<<endl;
    }
}

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

using namespace std;

int main(){
    int tt;
    cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<long long> arr(n);
        long long sum=0;
        for(int i=0; i<n; i++){
        cin>>arr[i];
        sum+=arr[i];
        }
        int cnt=0;
        // cout<<sum<<endl;
        while(n-cnt>1){
            cnt++;
            vector<long long>brr(n-cnt,0);
            long long ans=0;
            for(int i=1; i<n-cnt+1; i++){
                brr[i-1]=(arr[i]-arr[i-1]);
            }
            sum=max(sum,abs(brr[n-cnt-1]-brr[0]));
            swap(arr,brr);
        }
        if(n-cnt==1 && n!=1)
        sum=max(sum,abs(arr[0]));
        
        cout<<sum<<endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

using namespace std;

int main(){
    int tt;
    cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<long long> arr(n);
        long long sum=0;
        for(int i=0; i<n; i++){
        cin>>arr[i];
        sum+=arr[i];
        }
        int cnt=0;
        // cout<<sum<<endl;
        while(n-cnt>1){
            cnt++;
            vector<long long>brr(n-cnt,0);
            long long ans=0;
            for(int i=1; i<n-cnt+1; i++){
                brr[i-1]=(arr[i]-arr[i-1]);
            }
            sum=max(sum,abs(brr[n-cnt-1]-brr[0]));
            swap(arr,brr);
        }
        
        cout<<sum<<endl;
    }
}

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

using namespace std;

int main(){
    int tt;
    cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<long long> arr(n);
        long long sum=0;
        for(int i=0; i<n; i++){
        cin>>arr[i];
        sum+=arr[i];
        }
        int cnt=0;
        // cout<<sum<<endl;
        while(n-cnt>1){
            cnt++;
            vector<long long>brr(n-cnt,0);
            long long ans=0;
            for(int i=1; i<n-cnt+1; i++){
                brr[i-1]=(arr[i]-arr[i-1]);
            }
            sum=max(sum,abs(brr[n-cnt-1]-brr[0]));
            swap(arr,brr);
        }
        if(n-cnt==1)
        sum=max(sum,abs(arr[0]));
        
        cout<<sum<<endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


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

using namespace std;

int main(){
    int tt;
    cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<long long> arr(n);
        long long sum=0;
        for(int i=0; i<n; i++){
        cin>>arr[i];
        sum+=arr[i];
        }
        int cnt=0;
        // cout<<sum<<endl;
        while(n-cnt>1){
            cnt++;
            vector<long long>brr(n-cnt,0);
            long long ans=0;
            for(int i=1; i<n-cnt+1; i++){
                brr[i-1]=(arr[i]-arr[i-1]);
            }
            sum=max(sum,abs(brr[n-cnt-1]-brr[0]));
            swap(arr,brr);
        }
        
        cout<<sum<<endl;
    }
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Memory limit exceeded on test 14):
#include<iostream>
#include<vector>
#include<map>
#include<climits>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<unordered_set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define ll long long 

int helper(string a, string b, string c, int i, int j, int k, vector<vector<vector<int>>>& dp) {
    if (i == a.size()) {
        int idxc = k;
        int cnt = 0;
        for (int idx = j; idx < b.size(); idx++) {
            if (b[idx] != c[idxc]) {
                cnt++;
            }
            idxc++;
        }
        return cnt;
    }
    if (j == b.size()) {
        int idxc = k;
        int cnt = 0;
        for (int idx = i; idx < a.size(); idx++) {
            if (a[idx] != c[idxc]) {
                cnt++;
            }
            idxc++;
        }
        return cnt;
    }
    if (dp[i][j][k] != -1) {
        return dp[i][j][k];
    }
    int op1 = helper(a, b, c, i + 1, j, k + 1, dp) + ((a[i] == c[k]) ? 0 : 1);
    int op2 = helper(a, b, c, i, j + 1, k + 1, dp) + ((b[j] == c[k]) ? 0 : 1);
    return dp[i][j][k] = min(op1, op2);
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        int sa = a.size();
        int sb = b.size();
        int sc = c.size();
        vector<vector<vector<int>>> dp(sa + 1, vector<vector<int>>(sb + 1, vector<int>(sc + 1, -1)));
        cout << helper(a, b, c, 0, 0, 0, dp) << endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 16):
#include<iostream>
#include<vector>
#include<map>
#include<climits>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<unordered_set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define ll long long 
int helper(string a, string b, string c, int i, int j, vector<vector<int>> &dp) {
    if (i == a.size()) {
        int cnt = 0;
        for (int idx = j; idx < b.size(); idx++) {
            if (b[idx] != c[i + idx]) {
                cnt++;
            }
        }
        return cnt;
    }
    if (j == b.size()) {
        int cnt = 0;
        for (int idx = i; idx < a.size(); idx++) {
            if (a[idx] != c[idx + j]) {
                cnt++;
            }
        }
        return cnt;
    }
    if (dp[i][j] != -1) {
        return dp[i][j];
    }

    int op1 = helper(a, b, c, i + 1, j, dp) + ((a[i] == c[i + j]) ? 0 : 1);
    int op2 = helper(a, b, c, i, j + 1, dp) + ((b[j] == c[i + j]) ? 0 : 1);

    return dp[i][j] = min(op1, op2);
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        int sa = a.size();
        int sb = b.size();

        vector<vector<int>> dp(sa + 1, vector<int>(sb + 1, -1));
        cout << helper(a, b, c, 0, 0, dp) << endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include<iostream>
#include<vector>
#include<map>
#include<climits>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<unordered_set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define ll long long 
int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        int sa = a.size();
        int sb = b.size();

        vector<vector<int>> dp(sa + 1, vector<int>(sb + 1, INT_MAX));

        for (int i = 0; i <= sa; ++i) {
            for (int j = 0; j <= sb; ++j) {
                if (i + j > c.size()) continue;
                if (i == 0 && j == 0) {
                    dp[i][j] = 0;
                } else if (i == 0) {
                    dp[i][j] = dp[i][j - 1] + (b[j - 1] != c[i + j - 1]);
                } else if (j == 0) {
                    dp[i][j] = dp[i - 1][j] + (a[i - 1] != c[i + j - 1]);
                } else {
                    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[sa][sb] << endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Memory limit exceeded on test 14):
#include<iostream>
#include<vector>
#include<map>
#include<climits>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<unordered_set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define ll long long 

int helper(string a, string b, string c, int i, int j, int k, vector<vector<vector<int>>>& dp) {
    if (i == a.size()) {
        int idxc = k;
        int cnt = 0;
        for (int idx = j; idx < b.size(); idx++) {
            if (b[idx] != c[idxc]) {
                cnt++;
            }
            idxc++;
        }
        return cnt;
    }
    if (j == b.size()) {
        int idxc = k;
        int cnt = 0;
        for (int idx = i; idx < a.size(); idx++) {
            if (a[idx] != c[idxc]) {
                cnt++;
            }
            idxc++;
        }
        return cnt;
    }
    if (dp[i][j][k] != -1) {
        return dp[i][j][k];
    }
    int op1 = helper(a, b, c, i + 1, j, k + 1, dp) + ((a[i] == c[k]) ? 0 : 1);
    int op2 = helper(a, b, c, i, j + 1, k + 1, dp) + ((b[j] == c[k]) ? 0 : 1);
    return dp[i][j][k] = min(op1, op2);
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        int sa = a.size();
        int sb = b.size();
        int sc = c.size();
        vector<vector<vector<int>>> dp(sa + 1, vector<vector<int>>(sb + 1, vector<int>(sc + 1, -1)));
        cout << helper(a, b, c, 0, 0, 0, dp) << endl;
    }
    return 0;
}

Submission (verdict: Memory limit exceeded on test 14):
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        int sa = a.size();
        int sb = b.size();
        int sc = c.size();

        vector<vector<vector<int>>> dp(sa + 1, vector<vector<int>>(sb + 1, vector<int>(sc + 1, INT_MAX)));
        dp[0][0][0] = 0;

        for (int i = 0; i <= sa; ++i) {
            for (int j = 0; j <= sb; ++j) {
                for (int k = 0; k <= sc; ++k) {
                    if (k > i + j) continue;
                    if (i < sa && k < sc) { 
                        dp[i + 1][j][k + 1] = min(dp[i + 1][j][k + 1], dp[i][j][k] + (a[i] != c[k]));
                    }
                    if (j < sb && k < sc) { 
                        dp[i][j + 1][k + 1] = min(dp[i][j + 1][k + 1], dp[i][j][k] + (b[j] != c[k]));
                    }
                }
            }
        }
        cout << dp[sa][sb][sc] << endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Memory limit exceeded on test 14):
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        int sa = a.size();
        int sb = b.size();
        int sc = c.size();

        vector<vector<vector<int>>> dp(sa + 1, vector<vector<int>>(sb + 1, vector<int>(sc + 1, INT_MAX)));
        dp[0][0][0] = 0;

        for (int i = 0; i <= sa; ++i) {
            for (int j = 0; j <= sb; ++j) {
                for (int k = 0; k <= sc; ++k) {
                    if (k > i + j) continue;
                    if (i < sa && k < sc) { 
                        dp[i + 1][j][k + 1] = min(dp[i + 1][j][k + 1], dp[i][j][k] + (a[i] != c[k]));
                    }
                    if (j < sb && k < sc) { 
                        dp[i][j + 1][k + 1] = min(dp[i][j + 1][k + 1], dp[i][j][k] + (b[j] != c[k]));
                    }
                }
            }
        }
        cout << dp[sa][sb][sc] << endl;
    }
    return 0;
}


Submission (verdict: Time limit exceeded on test 16):
#include<iostream>
#include<vector>
#include<map>
#include<climits>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<unordered_set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define ll long long 
int helper(string a, string b, string c, int i, int j, vector<vector<int>> &dp) {
    if (i == a.size()) {
        int cnt = 0;
        for (int idx = j; idx < b.size(); idx++) {
            if (b[idx] != c[i + idx]) {
                cnt++;
            }
        }
        return cnt;
    }
    if (j == b.size()) {
        int cnt = 0;
        for (int idx = i; idx < a.size(); idx++) {
            if (a[idx] != c[idx + j]) {
                cnt++;
            }
        }
        return cnt;
    }
    if (dp[i][j] != -1) {
        return dp[i][j];
    }

    int op1 = helper(a, b, c, i + 1, j, dp) + ((a[i] == c[i + j]) ? 0 : 1);
    int op2 = helper(a, b, c, i, j + 1, dp) + ((b[j] == c[i + j]) ? 0 : 1);

    return dp[i][j] = min(op1, op2);
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        int sa = a.size();
        int sb = b.size();

        vector<vector<int>> dp(sa + 1, vector<int>(sb + 1, -1));
        cout << helper(a, b, c, 0, 0, dp) << endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
int helper(int i , int j, string a, string b , string c,vector<vector<int>> &dp) {
    if(i + j >= c.size()){
        return  dp[i][j] = 0 ;
    }
    int temp1 =1;
    if(a[i]==c[i+j]){
        temp1--;
    }
    int temp2 = 1;
    if(b[j] == c[i+j]){
        temp2--;
    }
    if(i==a.size()){
        
        return dp[i][j] = temp2 + helper(i , j+1 , a , b,c,dp);
    }
    if(j==b.size()){
       
        return dp[i][j] = temp1 + helper(i+1 , j , a , b,c,dp);
    }
    return dp[i][j] = min(temp1 + helper(i+1 , j , a , b,c,dp) ,temp2 + helper(i , j+1 , a , b,c,dp) );
}
int main()
{
    
    int n;
    cin>>n;
    
    while(n--)
    {
        string a  , b , c;
        cin>>a>>b>>c;
        vector<vector<int>> dp(a.size() + 1, vector<int> (b.size()+1));
        cout<<helper(0,0,a,b,c,dp);
        cout<<endl;
      

    }
    return 0;
}