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

Previous 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

*/


Submission (verdict: Compilation error):
#include <iostream>
#include <stack>

using namespace std;
vector<vector<int>> dp;
int rec(string &a, string &b, string &c, int i, int j) {
    if(i == a.size() && j == b.size()) return 0;
    int pos = i+j;
    int res = INT_MAX;
    if(i < a.length()) {
        int cost = rec(a,b,c,i+1,j) + (a[i] != c[pos]);
        res = min(res, cost);
    }
    if(j < b.length()) {
        int cost = rec(a,b,c,i,j+1) + (b[j] != c[pos]);
        res = min(res, cost);
    }
    return res;
}

int mem(string &a, string &b, string &c, int i, int j) {
    if(i == a.size() && j == b.size()) return 0;
    if(dp[i][j] != -1) return dp[i][j];
    int pos = i+j;
    int res = INT_MAX;
    if(i < a.length()) {
        int cost = mem(a,b,c,i+1,j) + (a[i] != c[pos]);
        res = min(res, cost);
    }
    if(j < b.length()) {
        int cost = mem(a,b,c,i,j+1) + (b[j] != c[pos]);
        res = min(res, cost);
    }
    return dp[i][j] = res;
}

int tab(string &a, string &b, string &c) {
    dp[a.length()][b.length()] = 0;
    for(int j=0;j<b.length(); j++) dp[a.length()][j] = 0;
    for(int i=0;i<a.length(); i++) dp[i][b.length()] = 0;
    for(int i=a.length()-1;i >= 0; i--) {
        for(int j=b.length()-1; j >= 0; j--) { 
            int pos = i+j;
            int res = INT_MAX;
            if(i < a.length()) {
                int cost = dp[i+1][j] + (a[i] != c[pos]);
                res = min(res, cost);
            }
            if(j < b.length()) {
                int cost = dp[i][j+1] + (b[j] != c[pos]);
                res = min(res, cost);
            }
            dp[i][j] = res;         
        }
    }
    return dp[0][0];
}
int main() {
    #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
    int t;
    cin >> t;
    string a, b, c;
    while (t--) {
        cin>>a>>b>>c; 
        dp.assign(a.length() + 1, vector<int> (b.length()+1, -1));
        //cout<<rec(a,b,c,0,0)<<'\n'
        cout<<mem(a,b,c,0,0)<<'\n';
        // cout<<tab(a,b,c)<<'\n';        
    }
}

/*
  
1 2 3 4 5
6 2 1 4 2
6 2 0 4 3
5 2 1 4 3
5 3 1 3 3
4 3 2 3 3
3 3 3 3 3

6 2 1 4 2
3 2 4 4 2
3 3 4 3 2
3 3 3 3 3

4 2 1 5 3

4 2 1 5 3
4 3 1 4 3

*/