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

Previous submission (verdict: Time limit exceeded on test 16):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int f(int i,int j,int k,vector<vector<int>>&dp,string a,string b,string c){
  if(i==a.length()&&j==b.length()){
    return 0;
  }
  if(dp[i][j]!=-1)return dp[i][j];
  if(i<a.length()&&j<b.length()){
    if(a[i]==b[j]){
      if(a[i]==c[k]){
        return dp[i][j]=min(f(i+1,j,k+1,dp,a,b,c),f(i,j+1,k+1,dp,a,b,c));
      }
      return dp[i][j]=1+min(f(i+1,j,k+1,dp,a,b,c),f(i,j+1,k+1,dp,a,b,c));
    }
    if(a[i]==c[k]){
      return dp[i][j]=min(f(i+1,j,k+1,dp,a,b,c),1+f(i,j+1,k+1,dp,a,b,c));
    }
    if(b[j]==c[k]){
        return dp[i][j]=min(1+f(i+1,j,k+1,dp,a,b,c),f(i,j+1,k+1,dp,a,b,c));
    }
    return dp[i][j]= 1+min(f(i+1,j,k+1,dp,a,b,c),f(i,j+1,k+1,dp,a,b,c));
  }
  if(i<a.length()){
 if(a[i]==c[k]){
      return dp[i][j]=f(i+1,j,k+1,dp,a,b,c);
    }
    return dp[i][j]=1+f(i+1,j,k+1,dp,a,b,c);
  }
    if(b[j]==c[k]){
        return dp[i][j]=f(i,j+1,k+1,dp,a,b,c);
    }
    return dp[i][j]= 1+f(i,j+1,k+1,dp,a,b,c);

}
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<<  f(0,0,0,dp,a,b,c);

   cout<<endl;


     
    }
    return 0;
}

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