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

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;


int recursion(string s1, string s2, string c, int index1, int index2, vector<vector<int>> &dp){
    if(index1==0 && index2 == 0) return dp[index1][index2] = 0;
    if(dp[index1][index2] != -1) return dp[index1][index2];

    int a = INT_MAX;
    if(index1 > 0){
        if(s1[index1-1] == c[index1 + index2 -1]){
            a = min(a, recursion(s1, s2, c, index1-1, index2, dp));
        }
        else {
            a = min(a, 1 + recursion(s1, s2, c, index1-1, index2, dp));
        }
    }
    if(index2 > 0){
        if(s2[index2-1] == c[index1+index2-1]){
            a = min(a, recursion(s1, s2, c, index1, index2-1, dp));
        }
        else {
            a = min(a, 1 + recursion(s1, s2, c, index1, index2-1, dp));
        }
    }
    return dp[index1][index2] = a;
    
}
void solve(){
    string s1, s2, c;
    cin>>s1>>s2>>c;

    int n1 = s1.size();
    int n2 = s2.size();

    vector<vector<int>> dp(n1+1, vector<int>(n2+1, -1));
    // for(int i=0; i<=n1; i++){
    //     for(int j=0; j<=n2; j++){
    //         if(i==0 && j==0) continue;

    //         if(i>0 && s1[i-1] == c[i+j-1]){
    //             dp[i][j] = dp[i-1][j];
    //         }
    //         else if (j>0 && s2[j-1] == c[i+j-1]) {
    //             dp[i][j] = dp[i][j-1];
    //         }
    //         else{
    //             dp[i][j] = 1 + min(dp[i][j-1], dp[i-1][j]);
    //         }
    //     }
    // }

    cout<<recursion(s1, s2, c, n1, n2)<<endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 16):
#include <bits/stdc++.h>
using namespace std;


int recursion(string s1, string s2, string c, int index1, int index2, vector<vector<int>> &dp){
    if(index1==0 && index2 == 0) return dp[index1][index2] = 0;
    if(dp[index1][index2] != -1) return dp[index1][index2];

    int a = INT_MAX;
    if(index1 > 0){
        if(s1[index1-1] == c[index1 + index2 -1]){
            a = min(a, recursion(s1, s2, c, index1-1, index2, dp));
        }
        else {
            a = min(a, 1 + recursion(s1, s2, c, index1-1, index2, dp));
        }
    }
    if(index2 > 0){
        if(s2[index2-1] == c[index1+index2-1]){
            a = min(a, recursion(s1, s2, c, index1, index2-1, dp));
        }
        else {
            a = min(a, 1 + recursion(s1, s2, c, index1, index2-1, dp));
        }
    }
    return dp[index1][index2] = a;
    
}
void solve(){
    string s1, s2, c;
    cin>>s1>>s2>>c;

    int n1 = s1.size();
    int n2 = s2.size();

    vector<vector<int>> dp(n1+1, vector<int>(n2+1, -1));
    // for(int i=0; i<=n1; i++){
    //     for(int j=0; j<=n2; j++){
    //         if(i==0 && j==0) continue;

    //         if(i>0 && s1[i-1] == c[i+j-1]){
    //             dp[i][j] = dp[i-1][j];
    //         }
    //         else if (j>0 && s2[j-1] == c[i+j-1]) {
    //             dp[i][j] = dp[i][j-1];
    //         }
    //         else{
    //             dp[i][j] = 1 + min(dp[i][j-1], dp[i-1][j]);
    //         }
    //     }
    // }

    cout<<recursion(s1, s2, c, n1, n2, dp)<<endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}