Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 15):
 
#pragma GCC optimize("O3,unroll-loops")
 
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define all(x) (x).begin(), (x).end()
 
typedef long long ll;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
ll combination(ll n, ll r, ll m, vector<ll>fact, vector<ll>ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}
ll getRandomNumber(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);}
 
#define input(a, n) for(int i = 0; i < n; i++){cin>>a[i];}
#define print(a, n) for(int i = 0; i < n; i++) {cout<<a[i]<<' ';}
/*--------------------------------------------------------------------------------------------------------------------------*/
#define int ll
int solve(int i, int j, string a, string b, string c, vector<vector<int>>& dp){
    if(i + j >= c.size()) return 0;
    if(dp[i][j] != 0) return dp[i][j];

    int l = (i < a.size()) ? (((a[i] == c[i+j]) ? 0 : 1) + solve(i+1, j, a, b, c, dp)) : 1e9;
    int r = (j < b.size()) ? ((b[j] == c[i+j] ? 0 : 1) + solve(i, j+1, a, b, c, dp)) : 1e9; 

    dp[i][j] = min(l, r);

    return dp[i][j];
}

void solve(){
    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, 0));

        int ans = solve(0, 0, a, b, c, dp);

        cout<<ans<<"\n";
    }
}
 
int32_t main(){
    fastio();
 
    solve();
    return 0;
}

Submission (verdict: Time limit exceeded on test 16):
 
#pragma GCC optimize("O3,unroll-loops")
 
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define all(x) (x).begin(), (x).end()
 
typedef long long ll;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
ll combination(ll n, ll r, ll m, vector<ll>fact, vector<ll>ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}
ll getRandomNumber(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);}
 
#define input(a, n) for(int i = 0; i < n; i++){cin>>a[i];}
#define print(a, n) for(int i = 0; i < n; i++) {cout<<a[i]<<' ';}
/*--------------------------------------------------------------------------------------------------------------------------*/
#define int ll
int solve(int i, int j, string a, string b, string c, vector<vector<int>>& dp){
    if(i + j >= c.size()) return 0;
    if(dp[i][j] != -1) return dp[i][j];

    int l = (i < a.size()) ? (((a[i] == c[i+j]) ? 0 : 1) + solve(i+1, j, a, b, c, dp)) : 1e9;
    int r = (j < b.size()) ? ((b[j] == c[i+j] ? 0 : 1) + solve(i, j+1, a, b, c, dp)) : 1e9; 

    dp[i][j] = min(l, r);

    return dp[i][j];
}

void solve(){
    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));

        int ans = solve(0, 0, a, b, c, dp);

        cout<<ans<<"\n";
    }
}
 
int32_t main(){
    fastio();
 
    solve();
    return 0;
}