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

Previous submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>
using namespace std;
vector<vector<vector<int>>> dp;
int maxm(int a, int b, int c) {
    int maxm = max(a,b);
    maxm = max(maxm,c);
    return maxm;
}
int recur(string &a, string &b, string &c, int i,int j, int k) {
    if(k >= c.length()) return maxm(0,a.length()-i,b.length()-j);
    if(i >= a.length() && j >= b.length()) return c.length() - k;
    if (i < a.length() && a[i] == c[k]) {
        return recur(a,b,c,i+1,j,k+1);
    } else if (j < b.length() && b[j] == c[k]) {
        return recur(a,b,c,i,j+1,k+1);
    } else if(i < a.length() && j < b.length()) {
        return 1+min(recur(a,b,c,i+1,j,k+1), recur(a,b,c,i,j+1,k+1));
    } else if(i < a.length()) {
        return min(recur(a,b,c,i+1,j,k), 1+recur(a,b,c,i,j,k+1));
    } else if(j < b.length()) {
        return min(recur(a,b,c,i,j+1,k), 1+recur(a,b,c,i,j,k+1));
    } else return 0;
}

int mem(string &a, string &b, string &c, int i,int j, int k) {
    if(k >= c.length()) return maxm(0,a.length()-i,b.length()-j);
    if(i >= a.length() && j >= b.length()) return c.length() - k;
    if(dp[i][j][k] != -1) return dp[i][j][k];
    if (i < a.length() && a[i] == c[k]) {
       return dp[i][j][k] = mem(a,b,c,i+1,j,k+1);
    } else if (j < b.length() && b[j] == c[k]) {
        return dp[i][j][k] = mem(a,b,c,i,j+1,k+1);
    } else if(i < a.length() && j < b.length()) {
        return dp[i][j][k] = 1+min(mem(a,b,c,i+1,j,k+1), mem(a,b,c,i,j+1,k+1));
    } else if(i < a.length()) {
        return dp[i][j][k] = min(mem(a,b,c,i+1,j,k),1+mem(a,b,c,i,j,k+1));
    } else if(j < b.length()) {
        return dp[i][j][k] = min(mem(a,b,c,i,j+1,k), 1+mem(a,b,c,i,j,k+1));
    } else return dp[i][j][k] = 0;
}

int main() {
	// your code goes here
    int t;
    cin>>t;
    while(t--) {
        string a, b, c;
        cin>>a>>b>>c;
       dp.resize(a.length(), vector<vector<int>> (b.length(), vector<int>(c.length(), -1)));
        cout<<mem(a,b,c,0,0,0)<<endl;
        //cout<<recur(a, b, c, 0, 0, 0)<<endl;
    }
}
/*
   i
egg
 j
annie
    k
egaegaeg
   1
  i
ab
 j
ba
    k
aabb
   
1
0
2
0
3
2
3

*/


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
vector<vector<vector<int>>> dp;
int maxm(int a, int b, int c) {
    int maxm = max(a,b);
    maxm = max(maxm,c);
    return maxm;
}
int recur(string &a, string &b, string &c, int i,int j, int k) {
    if(k >= c.length()) return maxm(0,a.length()-i,b.length()-j);
    if(i >= a.length() && j >= b.length()) return c.length() - k;
    if (i < a.length() && a[i] == c[k]) {
        return recur(a,b,c,i+1,j,k+1);
    } else if (j < b.length() && b[j] == c[k]) {
        return recur(a,b,c,i,j+1,k+1);
    } else if(i < a.length() && j < b.length()) {
        return 1+min(recur(a,b,c,i+1,j,k+1), recur(a,b,c,i,j+1,k+1));
    } else if(i < a.length()) {
        return min(recur(a,b,c,i+1,j,k), 1+recur(a,b,c,i,j,k+1));
    } else if(j < b.length()) {
        return min(recur(a,b,c,i,j+1,k), 1+recur(a,b,c,i,j,k+1));
    } else return 0;
}

int mem(string &a, string &b, string &c, int i,int j, int k) {
    if(k >= c.length()) return maxm(0,a.length()-i,b.length()-j);
    if(i >= a.length() && j >= b.length()) return c.length() - k;
    if(dp[i][j][k] != -1) return dp[i][j][k];
    if (i < a.length() && a[i] == c[k]) {
       return dp[i][j][k] = mem(a,b,c,i+1,j,k+1);
    } else if (j < b.length() && b[j] == c[k]) {
        return dp[i][j][k] = mem(a,b,c,i,j+1,k+1);
    } else if(i < a.length() && j < b.length()) {
        return dp[i][j][k] = 1+min(mem(a,b,c,i+1,j,k+1), mem(a,b,c,i,j+1,k+1));
    } else if(i < a.length()) {
        return dp[i][j][k] = min(mem(a,b,c,i+1,j,k),1+mem(a,b,c,i,j,k+1));
    } else if(j < b.length()) {
        return dp[i][j][k] = min(mem(a,b,c,i,j+1,k), 1+mem(a,b,c,i,j,k+1));
    } else return dp[i][j][k] = 0;
}

int main() {
	// your code goes here
    int t;
    cin>>t;
    while(t--) {
        string a, b, c;
        cin>>a>>b>>c;
      // dp.resize(a.length()+1, vector<vector<int>> (b.length()+1, vector<int>(c.length(), -1)));
       // cout<<mem(a,b,c,0,0,0)<<endl;
        cout<<recur(a, b, c, 0, 0, 0)<<endl;
    }
}
/*
   i
egg
 j
annie
    k
egaegaeg
   1
  i
ab
 j
ba
    k
aabb
   
1
0
2
0
3
2
3

*/