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

Previous submission (verdict: Time limit exceeded on test 16):
// #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;



// using ll = long long;

// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

// ll dfs(string s1, string s2, string s3, ll i, ll j, vector<vector<ll>> &dp)

// {

//     if (i >= s1.size() && j >= s2.size())

//     {

//         return 0;

//     }

//     ll ans = LONG_LONG_MAX;

//     if (i < s1.size())

//     {

//         ans = dfs(s1, s2, s3, i + 1, j, dp) + (s1[i] == s3[i + j] ? 0 : 1);

//     }

//     if (j < s2.size())

//     {

//         ans = min(ans, dfs(s1, s2, s3, i, j + 1, dp) + (s2[j] == s3[i + j] ? 0 : 1));

//     }

//     return ans;

// }

// void solve()

// {

//     string s1, s2, s3;

//     cin >> s1;

//     cin >> s2;

//     cin >> s3;

//     vector<vector<ll>> dp(s1.size(), vector<ll>(s2.size(), LONG_LONG_MAX));

//     cout << dfs(s1, s2, s3, 0, 0, dp) << endl;

// }

// int main()

// {



//     ios::sync_with_stdio(false);

//     cin.tie(0);

//     long long t;

//     cin >> t;



//     while (t--)

//     {

//         long long a, b, c;

//         // cin >> a ;

//         solve();

//     }



//     return 0;

// }



#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;



using ll = long long;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll dfs(string s1, string s2, string s3, ll i, ll j, vector<vector<ll>> &dp)

{



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

    {

        return dp[i][j];

    }

    ll ans = LONG_LONG_MAX;

    if (i < s1.size())

    {

        ans = dfs(s1, s2, s3, i + 1, j, dp) + (s1[i] == s3[i + j] ? 0 : 1);

    }

    if (j < s2.size())

    {

        ans = min(ans, dfs(s1, s2, s3, i, j + 1, dp) + (s2[j] == s3[i + j] ? 0 : 1));

    }

    dp[i][j] = ans;

    return ans;

}

void solve()

{

    string s1, s2, s3;

    cin >> s1;

    cin >> s2;

    cin >> s3;

    vector<vector<ll>> dp(s1.size() + 1, vector<ll>(s2.size() + 1, -1));

    dp[s1.size()][s2.size()] = 0;

    dfs(s1, s2, s3, 0, 0, dp);

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

}

int main()

{



    ios::sync_with_stdio(false);

    cin.tie(0);

    long long t;

    cin >> t;



    while (t--)

    {

        long long a, b, c;

        // cin >> a ;

        solve();

    }



    return 0;

}



Submission (verdict: Wrong answer on test 1):
// #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;



// using ll = long long;

// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

// ll dfs(string s1, string s2, string s3, ll i, ll j, vector<vector<ll>> &dp)

// {

//     if (i >= s1.size() && j >= s2.size())

//     {

//         return 0;

//     }

//     ll ans = LONG_LONG_MAX;

//     if (i < s1.size())

//     {

//         ans = dfs(s1, s2, s3, i + 1, j, dp) + (s1[i] == s3[i + j] ? 0 : 1);

//     }

//     if (j < s2.size())

//     {

//         ans = min(ans, dfs(s1, s2, s3, i, j + 1, dp) + (s2[j] == s3[i + j] ? 0 : 1));

//     }

//     return ans;

// }

// void solve()

// {

//     string s1, s2, s3;

//     cin >> s1;

//     cin >> s2;

//     cin >> s3;

//     vector<vector<ll>> dp(s1.size(), vector<ll>(s2.size(), LONG_LONG_MAX));

//     cout << dfs(s1, s2, s3, 0, 0, dp) << endl;

// }

// int main()

// {



//     ios::sync_with_stdio(false);

//     cin.tie(0);

//     long long t;

//     cin >> t;



//     while (t--)

//     {

//         long long a, b, c;

//         // cin >> a ;

//         solve();

//     }



//     return 0;

// }



#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;



using ll = long long;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll dfs(string &s1, string &s2, string &s3, ll i, ll j, vector<vector<ll>> &dp)

{



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

    {

        return dp[i][j];

    }

    ll ans = LONG_LONG_MAX;

    if (i < s1.size())

    {

        cout << "[" << i+1 << "," << j << "]" << endl;

        ans = dfs(s1, s2, s3, i + 1, j, dp) + (s1[i] == s3[i + j] ? 0 : 1);

    }

    if (j < s2.size())

    {

        cout << "[" << i << "," << j+1 << "]" << endl;

        ans = min(ans, dfs(s1, s2, s3, i, j + 1, dp) + (s2[j] == s3[i + j] ? 0 : 1));

    }

    dp[i][j] = ans;

    return ans;

}

void solve()

{

    string s1, s2, s3;

    cin >> s1;

    cin >> s2;

    cin >> s3;

    vector<vector<ll>> dp(s1.size() + 1, vector<ll>(s2.size() + 1, -1));

    dp[s1.size()][s2.size()] = 0;

    dfs(s1, s2, s3, 0, 0, dp);

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

}

int main()

{



    ios::sync_with_stdio(false);

    cin.tie(0);

    long long t;

    cin >> t;



    while (t--)

    {

        long long a, b, c;

        // cin >> a ;

        solve();

    }



    return 0;

}