Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Memory limit exceeded on test 14):
#include <iostream>
#include <vector>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
int minOperations(string a, string b, string c) {
    int n = a.length(), m = b.length(), l = c.length();
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(l + 1, INT_MAX)));

    // Base case: If i == n and j == m, cost is 0
    for (int k = 0; k <= l; ++k) {
        dp[n][m][k] = 0;
    }

    // Fill the DP table in reverse (bottom-up)
    for (int i = n; i >= 0; --i) {
        for (int j = m; j >= 0; --j) {
            for (int k = l; k >= 0; --k) {
                if (i == n && j == m) continue; // Already handled base case
                
                if (i < n && j < m) {
                    if (a[i] == b[j]) {
                        if (a[i] == c[k]) {
                            dp[i][j][k] = min(dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]);
                        } else {
                            dp[i][j][k] = 1 + min(dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]);
                        }
                    } else {
                        if (a[i] == c[k]) {
                            dp[i][j][k] = min(dp[i + 1][j][k + 1], 1 + dp[i][j + 1][k + 1]);
                        } else if (b[j] == c[k]) {
                            dp[i][j][k] = min(1 + dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]);
                        } else {
                            dp[i][j][k] = 1 + min(dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]);
                        }
                    }
                } else if (i < n) {
                    if (a[i] == c[k]) {
                        dp[i][j][k] = dp[i + 1][j][k + 1];
                    } else {
                        dp[i][j][k] = 1 + dp[i + 1][j][k + 1];
                    }
                } else if (j < m) {
                    if (b[j] == c[k]) {
                        dp[i][j][k] = dp[i][j + 1][k + 1];
                    } else {
                        dp[i][j][k] = 1 + dp[i][j + 1][k + 1];
                    }
                }
            }
        }
    }

    return dp[0][0][0]; // Final result
}

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


     cout<<   minOperations(a,b,c);

   cout<<endl;


     
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 16):
#include <iostream>
#include <vector>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
int minOperations(string a, string b, string c) {
    int n = a.length(), m = b.length(), l = c.length();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    vector<vector<int>> next(n + 1, vector<int>(m + 1, 0));

    // Iterate over k from l to 0
    for (int k = l; k >= 0; --k) {
        for (int i = n; i >= 0; --i) {
            for (int j = m; j >= 0; --j) {
                if (i == n && j == m) {
                    dp[i][j] = 0; // Base case
                } else if (i < n && j < m) {
                    if (a[i] == b[j]) {
                        if (k < l && a[i] == c[k]) {
                            dp[i][j] = min(next[i + 1][j], next[i][j + 1]);
                        } else {
                            dp[i][j] = 1 + min(next[i + 1][j], next[i][j + 1]);
                        }
                    } else {
                        if (k < l && a[i] == c[k]) {
                            dp[i][j] = min(next[i + 1][j], 1 + next[i][j + 1]);
                        } else if (k < l && b[j] == c[k]) {
                            dp[i][j] = min(1 + next[i + 1][j], next[i][j + 1]);
                        } else {
                            dp[i][j] = 1 + min(next[i + 1][j], next[i][j + 1]);
                        }
                    }
                } else if (i < n) {
                    if (k < l && a[i] == c[k]) {
                        dp[i][j] = next[i + 1][j];
                    } else {
                        dp[i][j] = 1 + next[i + 1][j];
                    }
                } else if (j < m) {
                    if (k < l && b[j] == c[k]) {
                        dp[i][j] = next[i][j + 1];
                    } else {
                        dp[i][j] = 1 + next[i][j + 1];
                    }
                }
            }
        }
        next = dp; // Move to the next layer
    }

    return dp[0][0];
}


int main(){
    int t;
    cin>>t;
    while(t--){
      
       string a,b,c;
       cin>>a>>b>>c;
vector<vector<int>>dp(a.length()+1,vector<int>(b.length()+1,-1));

     cout<<   minOperations(a,b,c);

   cout<<endl;


     
    }
    return 0;
}