Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
 
int recurrencia(string & a, string & b, string & c, int & elem, int ans, int ina, int inb){
    if(elem >= c.size()){
        return ans;
    }
    if(ina == a.size() && b.size() == inb){
        return ans;
    }
    if(ina == a.size()){
        for(int j = inb; j < b.size(); j++){
            if(b[j] != c[elem])
                ans++;
            elem++;
        }
        return ans;
    }
    else if(b.size() == inb){
        for(int j = ina; j<a.size(); j++){
            if(a[j] != c[elem])
                ans++;
            elem++;
        }
        return ans;
    }
    else if(c[elem] != a[ina] && c[elem] != b[inb]){
        elem++;
        ans++;
        int res1 = recurrencia(a, b, c, elem, ans, ina+1, inb);
        int res2 = recurrencia(a, b, c, elem, ans, ina, inb+1);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
    }
    else if(c[elem] == a[ina] && c[elem] == b[inb]){
        elem++;
        int res1 = recurrencia(a, b, c, elem, ans, ina+1, inb);
        int res2 = recurrencia(a, b, c, elem, ans, ina, inb+1);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
    }
    else if(c[elem] == a[ina]){
        elem++;
        int res1 = recurrencia(a, b, c, elem, ans, ina+1, inb);
        int res2 = recurrencia(a, b, c, elem, ans+1, ina, inb+1);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
    }
    else if(c[elem] == b[inb]){
        elem++;
        int res1 = recurrencia(a, b, c, elem, ans+1, ina+1, inb);
        int res2 = recurrencia(a, b, c, elem, ans, ina, inb+1);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
    }
    return ans;
}
 
signed main(){
    int t; cin >> t;
    for(int k = 0; k<t; k++){
        string a, b, c; cin >> a >> b >> c;
        int ans = 0;
        int elem = 0;
        int ina = 0;
        int inb = 0;
        cout << recurrencia(a, b, c, elem, ans, ina, inb) << endl;
    }
}

Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
 
int recurrencia(string & a, string & b, string & c, int  elem, int ans, int ina, int inb){
    if(elem >= c.size()){
        return ans;
    }
    if(ina == a.size() && b.size() == inb){
        return ans;
    }
    if(ina == a.size()){
        for(int j = inb; j < b.size(); j++){
            if(b[j] != c[elem])
                ans++;
            elem++;
        }
        return ans;
    }
    else if(b.size() == inb){
        for(int j = ina; j<a.size(); j++){
            if(a[j] != c[elem])
                ans++;
            elem++;
        }
        return ans;
    }
    else if(c[elem] != a[ina] && c[elem] != b[inb]){
        elem++;
        ans++;
        int res1 = recurrencia(a, b, c, elem, ans, ina+1, inb);
        int res2 = recurrencia(a, b, c, elem, ans, ina, inb+1);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
    }
    else if(c[elem] == a[ina] && c[elem] == b[inb]){
        elem++;
        int res1 = recurrencia(a, b, c, elem, ans, ina+1, inb);
        int res2 = recurrencia(a, b, c, elem, ans, ina, inb+1);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
    }
    else if(c[elem] == a[ina]){
        elem++;
        int res1 = recurrencia(a, b, c, elem, ans, ina+1, inb);
        int res2 = recurrencia(a, b, c, elem, ans+1, ina, inb+1);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
    }
    else if(c[elem] == b[inb]){
        elem++;
        int res1 = recurrencia(a, b, c, elem, ans+1, ina+1, inb);
        int res2 = recurrencia(a, b, c, elem, ans, ina, inb+1);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
    }
    return ans;
}
 
signed main(){
    int t; cin >> t;
    for(int k = 0; k<t; k++){
        string a, b, c; cin >> a >> b >> c;
        int ans = 0;
        int elem = 0;
        int ina = 0;
        int inb = 0;
        cout << recurrencia(a, b, c, elem, ans, ina, inb) << endl;
    }
}