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

Previous submission (verdict: Time limit exceeded on test 16):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl "\n"
#define int long long
#define pb push_back
#define cy cout <<"YES"<< endl
#define cn cout <<"NO"<< endl
#define all(x) x.begin(),x.end()
#define fastread std::ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int MOD = 1e18+7;
int ceil_div(int a, int b) { return a%b==0 ? a/b : a/b+1;}
int gcd(int a, int b) { if(a==0LL) { return b;} return gcd(b%a, a);}
int lcm(int a, int b) {return a*b/gcd(a,b);}

bool sorted(pair<int,int> &a, pair<int,int> &b) {
    if(a.first == b.first) 
        return a.second < b.second; // ascending
    return a.first > b.first; // descending
}

int exp(int a, int b) {
    if(b==0) return 1;
    int half_power = exp(a,b/2);
    a %= MOD;
    if(b%2==0) return half_power * half_power % MOD;
    else return half_power * half_power % MOD * (a%MOD) % MOD;
}

void SieveOfEratosthenes(int n) {
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
    for (int p = 2; p * p <= n; p++) {
        if (prime[p] == true) {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
}

int isPrime(int n) {
    for(int i=2; i*i<=n; i++) {
        if(n%i ==0)
            return false;
    }
    return true;
}

int fn(string a, string b, int i) {
    int count = 0;
    for(int j=i; j>=0; j--) {
        if(a[j] != b[j])
            count++;
    }
    return count;
}

int cf(string a, string b, string c, int i, int j, vector<vector<int>> &dp) {
    if(i==a.size() && j==b.size())
        return 0;
    if(dp[i][j] != -1)
        return dp[i][j];
    int pos = i+j, res = 1e9;
    if(i < a.size()) {
        int cos = cf(a,b,c,i+1,j,dp) + (a[i] != c[pos]);
        res = min(res, cos);
    }
    if(j < b.size()) {
        int cos = cf(a,b,c,i,j+1,dp) + (b[j] != c[pos]);
        res = min(res, cos);
    }
    return dp[i][j] = res;
}

void solve() {
    string a; cin >> a;
    string b; cin >> b;
    string c; cin >> c;
    int n = a.size(), m = b.size(), i = c.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1, -1));
    cout << cf(a,b,c,0,0,dp) << endl;
}

signed main() {
    fastread
    int t = 1; cin >> t;
    while(t--) {
        solve();
    }
}

Submission (verdict: Accepted):
#include <iostream>
#include <algorithm>

static const int inf = 1e9;

// not my solution, just checking if it gives tle or not

void solve() {
    std::string a, b, res;
    std::cin >> a >> b >> res;
    int n = (int) a.size(), m = (int) b.size();
    int dp[n + 1][m + 1];
    std::fill(&dp[0][0], &dp[0][0] + (n + 1) * (m + 1), inf);
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = dp[i][0] + (a[i] != res[i]);
    }
    for (int j = 0; j < m; j++) {
        dp[0][j + 1] = dp[0][j] + (b[j] != res[j]);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = std::min(dp[i - 1][j] + (a[i - 1] != res[i + j - 1]),
                                dp[i][j - 1] + (b[j - 1] != res[i + j - 1]));
        }
    }
    std::cout << dp[n][m] << std::endl;
}

int main() {
    int tests;
    std::cin >> tests;
    while (tests--) {
        solve();
    }
}