ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 3):
#include<bits/stdc++.h>
#define ll long long
using namespace std;

bool findEl(multiset <ll> &ms, ll val, vector <ll> k){
    if (val == 1){
        auto pt = ms.find(val);
        if (pt == ms.end()){
            return false;
        }
        else{
            k.push_back(val);
            ms.erase(pt);
            return true;
        }
    } 
    auto pt = ms.find(val);
    if (pt == ms.end()){
        //could not find val
        return findEl(ms,val/2,k)&&findEl(ms,val/2 + (val&1),k);
    }else{
        ms.erase(pt);
        return true;
    }

}


int main() {

    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        
        multiset <ll> m1,m2;

        for (int i = 0; i<n; i++){
            ll x;cin>>x;
            m1.insert(x);
        }
        for (int i = 0; i<m; i++){
            ll x;
            cin>>x;
            auto pt = m1.find(x);
            if (pt != m1.end()){
                m1.erase(pt);
            }else{
                m2.insert(x);
            }
        }

        for (auto it = m2.begin(); it!= m2.end(); it++){
            vector <ll> k;
            bool found = findEl(m1,*it,k);
            if (found){
                auto x = it;
                m2.erase(x);
            }else{
                for (ll i : k){
                    m1.insert(i);
                }
            }
        } 

        if (m1.size() == 0 && m2.size() == 0){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }

    return 0;
}

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define ll long long
using namespace std;

bool findEl(multiset <ll> &ms, ll val){
    if (val == 1){
        auto pt = ms.find(val);
        if (pt == ms.end()){
            return false;
        }
        else{
            ms.erase(pt);
            return true;
        }
    } 
    auto pt = ms.find(val);
    if (pt == ms.end()){
        //could not find val
        return findEl(ms,val/2)&&findEl(ms,val/2 + (val&1));
    }else{
        ms.erase(pt);
        return true;
    }

}


int main() {

    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        
        multiset <ll> m1,m2;

        for (int i = 0; i<n; i++){
            ll x;cin>>x;
            m1.insert(x);
        }
        for (int i = 0; i<m; i++){
            ll x;
            cin>>x;
            auto pt = m1.find(x);
            if (pt != m1.end()){
                m1.erase(pt);
            }else{
                m2.insert(x);
            }
        }

        bool bad = false;

        for (auto it = m2.begin(); it!= m2.end(); it++){
            if (findEl(m1,*it)){
                auto x = it;
                m2.erase(it);
            }else{
                bad = !bad;
                break;
            }
        } 

        if (m1.size() == 0 && m2.size() == 0 && !bad){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define ll long long
using namespace std;

bool findEl(multiset <ll> &ms, ll val){
    if (val == 1){
        auto pt = ms.find(val);
        if (pt == ms.end()){
            return false;
        }
        else{
            ms.erase(pt);
            return true;
        }
    } 
    auto pt = ms.find(val);
    if (pt == ms.end()){
        //could not find val
        return findEl(ms,val/2)&&findEl(ms,val/2 + (val&1));
    }else{
        ms.erase(pt);
        return true;
    }

}


int main() {

    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        
        multiset <ll> m1,m2;

        for (int i = 0; i<n; i++){
            ll x;cin>>x;
            m1.insert(x);
        }
        for (int i = 0; i<m; i++){
            ll x;
            cin>>x;
            auto pt = m1.find(x);
            if (pt != m1.end()){
                m1.erase(pt);
            }else{
                m2.insert(x);
            }
        }

        bool bad = false;

        for (auto it = m2.begin(); it!= m2.end(); it++){
            if (findEl(m1,*it)){
                auto x = it;
                m2.erase(x);
            }else{
                bad = true;
                break;
            }
        } 

        if (m1.size() == 0 && m2.size() == 0 && !bad){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }

    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
#define ll long long
using namespace std;

bool findEl(multiset <ll> &ms, ll val){
    if (val == 1){
        auto pt = ms.find(val);
        if (pt == ms.end()){
            return false;
        }
        else{
            ms.erase(pt);
            return true;
        }
    } 
    auto pt = ms.find(val);
    if (pt == ms.end()){
        //could not find val
        return findEl(ms,val/2)&&findEl(ms,val/2 + (val&1));
    }else{
        ms.erase(pt);
        return true;
    }

}


int main() {

    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        
        multiset <ll> m1,m2;

        for (int i = 0; i<n; i++){
            ll x;cin>>x;
            m1.insert(x);
        }
        for (int i = 0; i<m; i++){
            ll x;
            cin>>x;
            auto pt = m1.find(x);
            if (pt != m1.end()){
                m1.erase(pt);
            }else{
                m2.insert(x);
            }
        }

        bool bad = false;

        for (auto it = m2.begin(); it!= m2.end();){
            if (findEl(m1,*it)){
                auto x = it;
                it = m2.erase(x);
            }else{
                bad = true;
                break;
            }
        } 

        if (m1.size() == 0 && m2.size() == 0 && !bad){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define ll long long
using namespace std;

bool findEl(multiset <ll> &ms, ll val){
    if (val == 1){
        auto pt = ms.find(val);
        if (pt == ms.end()){
            return false;
        }
        else{
            ms.erase(pt);
            return true;
        }
    } 
    auto pt = ms.find(val);
    if (pt == ms.end()){
        //could not find val
        return findEl(ms,val/2)&&findEl(ms,val/2 + (val&1));
    }else{
        ms.erase(pt);
        return true;
    }

}


int main() {

    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        
        multiset <ll> m1,m2;

        for (int i = 0; i<n; i++){
            ll x;cin>>x;
            m1.insert(x);
        }
        for (int i = 0; i<m; i++){
            ll x;
            cin>>x;
            auto pt = m1.find(x);
            if (pt != m1.end()){
                m1.erase(pt);
            }else{
                m2.insert(x);
            }
        }

        bool bad = false;

        for (auto it = m2.begin(); it!= m2.end(); it++){
            if (findEl(m1,*it)){
                auto x = it;
                m2.erase(it);
            }else{
                bad = !bad;
                break;
            }
        } 

        if (m1.size() == 0 && m2.size() == 0 && !bad){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }

    return 0;
}

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define ll long long
using namespace std;

bool findEl(multiset <ll> &ms, ll val){
    if (val == 1){
        auto pt = ms.find(val);
        if (pt == ms.end()){
            return false;
        }
        else{
            ms.erase(pt);
            return true;
        }
    } 
    auto pt = ms.find(val);
    if (pt == ms.end()){
        //could not find val
        return findEl(ms,val/2)&&findEl(ms,val/2 + (val&1));
    }else{
        ms.erase(pt);
        return true;
    }

}


int main() {

    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        
        multiset <ll> m1,m2;

        for (int i = 0; i<n; i++){
            ll x;cin>>x;
            m1.insert(x);
        }
        for (int i = 0; i<m; i++){
            ll x;
            cin>>x;
            auto pt = m1.find(x);
            if (pt != m1.end()){
                m1.erase(pt);
            }else{
                m2.insert(x);
            }
        }

        bool bad = false;

        for (auto it = m2.begin(); it!= m2.end(); it++){
            if (findEl(m1,*it)){
                auto x = it;
                m2.erase(x);
            }else{
                bad = true;
                break;
            }
        } 

        if (m1.size() == 0 && m2.size() == 0 && !bad){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }

    return 0;
}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pi 3.1415926

#define pb(e) push_back(e)

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

#define cin(v) for(auto &i:v){cin>>i;}

#define sv(a) sort(a.begin(),a.end())

#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL));

#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++)

#define vi vector<int> 

#define vii vector<vector<int>>

#define vc vector<char> 

#define vcc vector<vector<char>> 

void print(vector<int> v) {

for (auto i : v) cout << i << ' ';

cout << endl;}

 

 

int binpow(int a,int b){

int res=1;

while(b>0){

if(b&1)

res*=a; 

a*=a;

b>>=1;}

return res;}



int mex(vi f,vi ans) {

    vi v;

    forn(i,f.size()) {

        v.pb(ans[f[i]]);

    }

    int mex=0;

    sv(v);

    forn(i,v.size()) if(v[i]==mex) mex++;

    return mex;

}



void solve(){

    int n,x,y;

    cin>>n>>x>>y;

    vi ans(n,1e9);

    vii f(n);

    forn(i,n) {

        f[i].pb((i==0)?n-1:i-1);

        f[i].pb((i==n-1)?0:i+1);

    }

    x--;y--;

    f[x].pb(y);

    f[y].pb(x);

    forn(i,n) {

        ans[i]=mex(f[i],ans);

    }

    print(ans);

}

 

 

signed main(){

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

}

Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pi 3.1415926

#define pb(e) push_back(e)

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

#define cin(v) for(auto &i:v){cin>>i;}

#define sv(a) sort(a.begin(),a.end())

#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL));

#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++)

#define vi vector<int> 

#define vii vector<vector<int>>

#define vc vector<char> 

#define vcc vector<vector<char>> 

void print(vector<int> v) {

for (auto i : v) cout << i << ' ';

cout << endl;}

 

 

int binpow(int a,int b){

int res=1;

while(b>0){

if(b&1)

res*=a; 

a*=a;

b>>=1;}

return res;}



int mex(vi f,vi ans) {

    set<int> v;

    forn(i,f.size()) {

        v.insert(ans[f[i]]);

    }

    int mex=0;

    for(auto i:v) if(i==mex) mex++;

    return mex;

}



void solve(){

    int n,x,y;

    cin>>n>>x>>y;

    vi ans(n,1e9);

    vii f(n);

    forn(i,n) {

        f[i].pb((i==0)?n-1:i-1);

        f[i].pb((i==n-1)?0:i+1);

    }

    x--;y--;

    f[x].pb(y);

    f[y].pb(x);

    forn(i,n) {

        ans[i]=mex(f[i],ans);

    }

    print(ans);

}

 

 

signed main(){

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

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pi 3.1415926

#define pb(e) push_back(e)

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

#define cin(v) for(auto &i:v){cin>>i;}

#define sv(a) sort(a.begin(),a.end())

#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL));

#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++)

#define vi vector<int> 

#define vii vector<vector<int>>

#define vc vector<char> 

#define vcc vector<vector<char>> 

void print(vector<int> v) {

for (auto i : v) cout << i << ' ';

cout << endl;}

 

 

int binpow(int a,int b){

int res=1;

while(b>0){

if(b&1)

res*=a; 

a*=a;

b>>=1;}

return res;}



int mex(vi f,vi ans) {

    vi v;

    forn(i,f.size()) {

        v.pb(ans[f[i]]);

    }

    int mex=0;

    sv(v);

    forn(i,v.size()) if(v[i]==mex) mex++;

    return mex;

}



void solve(){

    int n,x,y;

    cin>>n>>x>>y;

    vi ans(n,1e9);

    vii f(n);

    forn(i,n) {

        f[i].pb((i==0)?n-1:i-1);

        f[i].pb((i==n-1)?0:i+1);

    }

    x--;y--;

    f[x].pb(y);

    f[y].pb(x);

    forn(i,n) {

        ans[i]=mex(f[i],ans);

    }

    print(ans);

}

 

 

signed main(){

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

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pi 3.1415926

#define pb(e) push_back(e)

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

#define cin(v) for(auto &i:v){cin>>i;}

#define sv(a) sort(a.begin(),a.end())

#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL));

#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++)

#define vi vector<int> 

#define vii vector<vector<int>>

#define vc vector<char> 

#define vcc vector<vector<char>> 

void print(vector<int> v) {

for (auto i : v) cout << i << ' ';

cout << endl;}

 

 

int binpow(int a,int b){

int res=1;

while(b>0){

if(b&1)

res*=a; 

a*=a;

b>>=1;}

return res;}



int mex(vi f,vi ans) {

    set<int> v;

    forn(i,f.size()) {

        v.insert(ans[f[i]]);

    }

    int mex=0;

    for(auto i:v) if(i==mex) mex++;

    return mex;

}



void solve(){

    int n,x,y;

    cin>>n>>x>>y;

    vi ans(n,1e9);

    vii f(n);

    forn(i,n) {

        f[i].pb((i==0)?n-1:i-1);

        f[i].pb((i==n-1)?0:i+1);

    }

    x--;y--;

    f[x].pb(y);

    f[y].pb(x);

    forn(i,n) {

        ans[i]=mex(f[i],ans);

    }

    print(ans);

}

 

 

signed main(){

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

}

Submission (verdict: Time limit exceeded on test 3):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pi 3.1415926

#define pb(e) push_back(e)

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

#define cin(v) for(auto &i:v){cin>>i;}

#define sv(a) sort(a.begin(),a.end())

#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL));

#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++)

#define vi vector<int> 

#define vii vector<vector<int>>

#define vc vector<char> 

#define vcc vector<vector<char>> 

void print(vector<int> v) {

for (auto i : v) cout << i << ' ';

cout << endl;}

 

 

int binpow(int a,int b){

int res=1;

while(b>0){

if(b&1)

res*=a; 

a*=a;

b>>=1;}

return res;}



int mex(vii f,vi ans,int j) {

    set<int> v;

    forn(i,f[j].size()) {

        v.insert(ans[f[j][i]]);

        // cout<<ans[f[j][i]]<<endl;

    }

    int mex=0;

    for(auto i:v) if(i==mex) mex++;

    return mex;

}



void solve(){

    int n,x,y;

    cin>>n>>x>>y;

    vi ans(n,1e9);

    vii f(n);

    forn(i,n) {

        f[i].pb((i==0)?n-1:i-1);

        f[i].pb((i==n-1)?0:i+1);

    }

    x--;y--;

    f[x].pb(y);

    f[y].pb(x);

    forn(i,n) {

        ans[i]=mex(f,ans,i);

    }

    print(ans);

}

 

 

signed main(){

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

}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 3):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pi 3.1415926

#define pb(e) push_back(e)

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

#define cin(v) for(auto &i:v){cin>>i;}

#define sv(a) sort(a.begin(),a.end())

#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL));

#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++)

#define vi vector<int> 

#define vii vector<vector<int>>

#define vc vector<char> 

#define vcc vector<vector<char>> 

void print(vector<int> v) {

for (auto i : v) cout << i << ' ';

cout << endl;}

 

 

int binpow(int a,int b){

int res=1;

while(b>0){

if(b&1)

res*=a; 

a*=a;

b>>=1;}

return res;}



int mex(vii f,vi ans,int j) {

    set<int> v;

    forn(i,f[j].size()) {

        v.insert(ans[f[j][i]]);

        // cout<<ans[f[j][i]]<<endl;

    }

    int mex=0;

    for(auto i:v) if(i==mex) mex++;

    return mex;

}



void solve(){

    int n,x,y;

    cin>>n>>x>>y;

    vi ans(n,1e9);

    vii f(n);

    forn(i,n) {

        f[i].pb((i==0)?n-1:i-1);

        f[i].pb((i==n-1)?0:i+1);

    }

    x--;y--;

    f[x].pb(y);

    f[y].pb(x);

    forn(i,n) {

        ans[i]=mex(f,ans,i);

    }

    print(ans);

}

 

 

signed main(){

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

}

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

using namespace std;

#define int long long

#define pi 3.1415926

#define pb(e) push_back(e)

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

#define cin(v) for(auto &i:v){cin>>i;}

#define sv(a) sort(a.begin(),a.end())

#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL));

#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++)

#define vi vector<int> 

#define vii vector<vector<int>>

#define vc vector<char> 

#define vcc vector<vector<char>> 

void print(vector<int> v) {

for (auto i : v) cout << i << ' ';

cout << endl;}

 

 

int binpow(int a,int b){

int res=1;

while(b>0){

if(b&1)

res*=a; 

a*=a;

b>>=1;}

return res;}



void solve(){

    int n,x,y;

    cin>>n>>x>>y;

    x--;y--;

    vi ans(n);

    forn(i,n) ans[(x+i)%n]=i%2;

    if(n%2||(x-y)%2==0)

        ans[x]=2;

    print(ans);

}

 

 

signed main(){

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

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;



void solve() {

int n;

cin >> n;

vector<int> a(n);

for(int &x : a) cin >> x;



int down = 0;

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

if(a[i] > a[i+1]) {

down++;

if(down > 1) break;

}

else down=0;



}



if(down <= 1) cout << "YES\n";

else cout << "NO\n";

}



int main() {

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) solve();

}



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

using namespace std;



void solve() {

int n;

cin >> n;

vector<int> a(n);

for(int &x : a) cin >> x;



int down = 0;

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

if(a[i] > a[i+1]) {

down++;

if(down > 1) break;

}

else down=0;



}

if(n==2 & a[1]>=a[0])cout<<"YES"<<endl;

else if(down <= 1) cout << "YES\n";



else cout << "NO\n";

}



int main() {

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) solve();

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;



void solve() {

int n;

cin >> n;

vector<int> a(n);

for(int &x : a) cin >> x;



int down = 0;

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

if(a[i] > a[i+1]) {

down++;

if(down > 1) break;

}

else down=0;



}



if(down <= 1) cout << "YES\n";

else cout << "NO\n";

}



int main() {

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) solve();

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;



void solve() {

int n;

cin >> n;

vector<int> a(n);

for(int &x : a) cin >> x;



int down = 0;

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

if(a[i] > a[i+1]) {

down++;

if(down > 1) break;

}

else down=0;



}

if(n==2 & a[1]>=a[0])cout<<"YES"<<endl;

else if(down <= 1) cout << "YES\n";



else cout << "NO\n";

}



int main() {

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while (t--) solve();

}



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

using namespace std;

#define ll long long

void solve()

{

ll n;cin>>n;vector<ll>v(n);

for(auto &x:v)cin>>x;

for(ll i=0;i<n-1;i++)

{

if(v[i]>v[i+1]) {cout<<"NO"<<'\n';return;}

v[i+1]-=v[i];

v[i]=0;

}

for(ll i=0;i<n-1;i++) {if(v[i]>v[i+1]){cout<<"NO"<<'\n';return;}}

cout<<"YES"<<'\n';

}

int main()

{

ll t;

cin>>t;

while(t--) 	solve();

return 0;

}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int solve(string &a,string &b,string &c,int i,int j,vector<vector<int>>&dp){
  if(i==a.length() && j==b.length()) return 0;
  if(dp[i][j]!=-1) return dp[i][j];
  int ans=0;
  if(i==a.length() && b[j]==c[i+j]) ans=0+solve(a,b,c,i,j+1,dp);
  if(i==a.length() && b[j]!=c[i+j]) ans=1+solve(a,b,c,i,j+1,dp);
  if(j==b.length() && a[i]==c[i+j]) ans=0+solve(a,b,c,i+1,j,dp);
  if(j==b.length() && a[i]!=c[i+j]) ans=1+solve(a,b,c,i+1,j,dp);
  if(i!=a.length()&&b[j]==c[i+j]) ans=0+min(0+solve(a,b,c,i,j+1,dp),1+solve(a,b,c,i+1,j,dp));
  if(j!=b.length()&&a[i]==c[i+j]){
   ans=0+min(0+solve(a,b,c,i+1,j,dp),1+solve(a,b,c,i,j+1,dp)); 
  }
  if(i!=a.length()&&j!=b.length()&&a[i]!=c[i+j]&&b[j]!=c[i+j]){
   ans=1+min(solve(a,b,c,i,j+1,dp),solve(a,b,c,i+1,j,dp));
   //cout<<b[j]<<endl;
  }
  dp[i][j]=ans;
  return dp[i][j];
}
int main() {
  int t;
  cin>>t;
  while(t--){
    string a,b,c;
    cin>>a>>b>>c;
    int i=0;
    int j=0;
    vector<vector<int>>dp(a.length()+1,vector<int>(b.length()+1,-1));
    int ans=solve(a,b,c,i,j,dp);
    cout<<ans<<endl;
  }
  return 0;
}

Submission (verdict: Wrong answer on test 4):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int solve(string &a,string &b,string &c,int i,int j,vector<vector<int>>&dp){
  if(i==a.length() && j==b.length()) return 0;
  if(dp[i][j]!=-1) return dp[i][j];
  int ans=0;
  if(i==a.length() && b[j]==c[i+j]) ans=0+solve(a,b,c,i,j+1,dp);
  if(i==a.length() && b[j]!=c[i+j]) ans=1+solve(a,b,c,i,j+1,dp);
  if(j==b.length() && a[i]==c[i+j]) ans=0+solve(a,b,c,i+1,j,dp);
  if(j==b.length() && a[i]!=c[i+j]) ans=1+solve(a,b,c,i+1,j,dp);
  if(i!=a.length()&&j!=b.length()&&a[i]==c[i+j]&&b[j]==c[i+j]) ans=0+min(solve(a,b,c,i,j+1,dp),solve(a,b,c,i+1,j,dp));
  if(i!=a.length()&&b[j]==c[i+j]) ans=0+min(0+solve(a,b,c,i,j+1,dp),1+solve(a,b,c,i+1,j,dp));
  if(j!=b.length()&&a[i]==c[i+j]){
   ans=0+min(0+solve(a,b,c,i+1,j,dp),1+solve(a,b,c,i,j+1,dp)); 
  }
  if(i!=a.length()&&j!=b.length()&&a[i]!=c[i+j]&&b[j]!=c[i+j]){
   ans=1+min(solve(a,b,c,i,j+1,dp),solve(a,b,c,i+1,j,dp));
   //cout<<b[j]<<endl;
  }
  dp[i][j]=ans;
  return dp[i][j];
}
int main() {
  int t;
  cin>>t;
  while(t--){
    string a,b,c;
    cin>>a>>b>>c;
    int i=0;
    int j=0;
    vector<vector<int>>dp(a.length()+1,vector<int>(b.length()+1,-1));
    int ans=solve(a,b,c,i,j,dp);
    cout<<ans<<endl;
  }
  return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 4):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int solve(string &a,string &b,string &c,int i,int j,vector<vector<int>>&dp){
  if(i==a.length() && j==b.length()) return 0;
  if(dp[i][j]!=-1) return dp[i][j];
  int ans=0;
  if(i==a.length() && b[j]==c[i+j]) ans=0+solve(a,b,c,i,j+1,dp);
  if(i==a.length() && b[j]!=c[i+j]) ans=1+solve(a,b,c,i,j+1,dp);
  if(j==b.length() && a[i]==c[i+j]) ans=0+solve(a,b,c,i+1,j,dp);
  if(j==b.length() && a[i]!=c[i+j]) ans=1+solve(a,b,c,i+1,j,dp);
  if(i!=a.length()&&b[j]==c[i+j]) ans=0+min(0+solve(a,b,c,i,j+1,dp),1+solve(a,b,c,i+1,j,dp));
  if(j!=b.length()&&a[i]==c[i+j]){
   ans=0+min(0+solve(a,b,c,i+1,j,dp),1+solve(a,b,c,i,j+1,dp)); 
  }
  if(i!=a.length()&&j!=b.length()&&a[i]!=c[i+j]&&b[j]!=c[i+j]){
   ans=1+min(solve(a,b,c,i,j+1,dp),solve(a,b,c,i+1,j,dp));
   //cout<<b[j]<<endl;
  }
  dp[i][j]=ans;
  return dp[i][j];
}
int main() {
  int t;
  cin>>t;
  while(t--){
    string a,b,c;
    cin>>a>>b>>c;
    int i=0;
    int j=0;
    vector<vector<int>>dp(a.length()+1,vector<int>(b.length()+1,-1));
    int ans=solve(a,b,c,i,j,dp);
    cout<<ans<<endl;
  }
  return 0;
}