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

Previous submission (verdict: Memory limit exceeded on test 14):
// #include <iostream>        // For input/output
// #include <vector>          // For using std::vector
// #include <tuple>           // For using std::tuple
// #include <algorithm>       // For sorting and other algorithms
// #include <queue>           // For std::queue and std::priority_queue
// #include <unordered_map>   // For std::unordered_map
// #include <string>          // For std::string
// #include <cmath>           // For std::pow
// using namespace std;

// int main(){
//     cout<<"hello"<<"\n";
//     return 0;
// }




#include <bits/stdc++.h>
using namespace std;

vector<vector<vector<int>>> dp;

int solve(int i, int j, int k, string &a, string &b, string &c, int &an, int &bn, int &cn) {
    if (k == cn) return 0;

    if (i == an || j == bn) {
        int ct = 0;
        if (i == an) {
            for (int g = j; g < bn; g++) {
                if (b[g] != c[k]) ct++;
                k++;
            }
            if (k < cn) ct += (cn - k);
        } else {
            for (int g = i; g < an; g++) {
                if (a[g] != c[k]) ct++;
                k++;
            }
            if (k < cn) ct += (cn - k);
        }
        return ct;
    }

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

    int res = INT_MAX;

    if (i < an) {
        int cost = (a[i] != c[k]) + solve(i + 1, j, k + 1, a, b, c, an, bn, cn);
        res = min(res, cost);
    }

    if (j < bn) {
        int cost = (b[j] != c[k]) + solve(i, j + 1, k + 1, a, b, c, an, bn, cn);
        res = min(res, cost);
    }

    return dp[i][j][k] = res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;

        int an = a.size(), bn = b.size(), cn = c.size();

        dp.assign(an + 1, vector<vector<int>>(bn + 1, vector<int>(cn + 1, -1)));

        cout << solve(0, 0, 0, a, b, c, an, bn, cn) << "\n";
    }
    return 0;
}


Submission (verdict: Accepted):
// #include <iostream>        // For input/output
// #include <vector>          // For using std::vector
// #include <tuple>           // For using std::tuple
// #include <algorithm>       // For sorting and other algorithms
// #include <queue>           // For std::queue and std::priority_queue
// #include <unordered_map>   // For std::unordered_map
// #include <string>          // For std::string
// #include <cmath>           // For std::pow
// using namespace std;

// int main(){
//     cout<<"hello"<<"\n";
//     return 0;
// }




#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> dp;

int solve(int i, int j, string &a, string &b, string &c, int &an, int &bn, int &cn) {
	int k = i+j;
    if (k == cn) return 0;

    if (i == an || j == bn) {
        int ct = 0;
        if (i == an) {
            for (int g = j; g < bn; g++) {
                if (b[g] != c[k]) ct++;
                k++;
            }
            if (k < cn) ct += (cn - k);
        } else {
            for (int g = i; g < an; g++) {
                if (a[g] != c[k]) ct++;
                k++;
            }
            if (k < cn) ct += (cn - k);
        }
        return ct;
    }

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

    int res = INT_MAX;

    if (i < an) {
        int cost = (a[i] != c[k]) + solve(i + 1,j, a, b, c, an, bn, cn);
        res = min(res, cost);
    }

    if (j < bn) {
        int cost = (b[j] != c[k]) + solve(i, j + 1, a, b, c, an, bn, cn);
        res = min(res, cost);
    }

    return dp[i][j] = res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;

        int an = a.size(), bn = b.size(), cn = c.size();

        dp.assign(an + 1, vector<int>(bn + 1, -1));

        cout << solve(0, 0, a, b, c, an, bn, cn) << "\n";
    }
    return 0;
}