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

Previous submission (verdict: Wrong answer on test 2):
//Jai Shree Ram

//Author : Meet Upadhyay

#include<bits/stdc++.h>

#include<unordered_set>

#define lli long long int

const lli MOD=1e9+7 ;

const lli MOD2= 998244353; 

const lli inf=1e18; 

bool sortbysec(const std::pair<int,int> &a,const std::pair<int,int> &b) { return (a.second < b.second); } 

lli power(lli n,lli a){ lli res=1; while(a){ if(a%2) res*=n,a--; else   n*=n,a/=2;} return res;}

lli modpower(lli n,lli a,lli p){ lli res=1; while(a){ if(a%2) res= ((res*n)%p) ,a--; else n=((n*n)%p),a/=2;} return res;}

lli fastprime(lli a){ if (a != 2 && a % 2 == 0 || a < 2) return 0;  for(lli i = 3; i * i <= a; i += 2) if(a % i == 0) return 0; return 1;}  

lli mod_mul_inverse(lli a,lli b) {return modpower(a , b-2, b);}

using namespace std;



template <unsigned int MOD>

struct ModInt {

using uint = unsigned int;

using ull = unsigned long long;

using M = ModInt;

uint v;

ModInt(lli _v = 0) { set_norm(_v % MOD + MOD); }

M& set_norm(uint _v) {  //[0, MOD * 2)->[0, MOD)

v = (_v < MOD) ? _v : _v - MOD;

return *this;

}

explicit operator bool() const { return v != 0; }

M operator+(const M& a) const { return M().set_norm(v + a.v); }

M operator-(const M& a) const { return M().set_norm(v + MOD - a.v); }

M operator*(const M& a) const { return M().set_norm(ull(v) * a.v % MOD); }

M operator/(const M& a) const { return *this * a.inv(); }

M& operator+=(const M& a) { return *this = *this + a; }

M& operator-=(const M& a) { return *this = *this - a; }

M& operator*=(const M& a) { return *this = *this * a; }

M& operator/=(const M& a) { return *this = *this / a; }

M operator-() const { return M() - *this; }

M& operator++(int) { return *this = *this + 1; }

M& operator--(int) { return *this = *this - 1; }

M pow(lli n) const {

if (n < 0) return inv().pow(-n);

M x = *this, res = 1;

while (n) {

if (n & 1) res *= x;

x *= x;

n >>= 1;

}

return res;

}

M inv() const {

lli a = v, b = MOD, p = 1, q = 0, t;

while (b != 0) {

t = a / b;

swap(a -= t * b, b);

swap(p -= t * q, q);

}

return M(p);

}

bool operator==(const M& a) const { return v == a.v; }

bool operator!=(const M& a) const { return v != a.v; }

friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; }

static uint get_mod() { return MOD; }

};

;

using Mint = ModInt<1000000007>;

void solve()

{

    string a;

    cin>>a;

    string b;

    cin>>b;

    string c;

    cin>>c;

    lli n = a.size();

    lli m = b.size();

    vector<vector<lli>>dp(n+5, vector<lli>(m+5,1e14));

    dp[0][0] = 0;

    for(lli i=0;i<n;i++)

    {

        dp[i+1][0] = dp[i][0] + (a[i]!=c[i]);

    }



    for(lli i=0;i<n;i++)

    {

        dp[0][i+1] = dp[0][i] + (b[i]!=c[i]);

    }



    for(lli i=1;i<=n;i++)

    {

        for(lli j=1;j<=m;j++)

        {

            dp[i][j] = min(dp[i-1][j] + (a[i-1]!=c[i+j-1]), dp[i][j-1] + (b[j-1]!=c[i+j-1]));

        }

    }



    cout<<dp[n][m]<<endl;



}

int main()

{

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;

    cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

}

Submission (verdict: Accepted):
//Jai Shree Ram

//Author : Meet Upadhyay

#include<bits/stdc++.h>

#include<unordered_set>

#define lli long long int

const lli MOD=1e9+7 ;

const lli MOD2= 998244353; 

const lli inf=1e18; 

bool sortbysec(const std::pair<int,int> &a,const std::pair<int,int> &b) { return (a.second < b.second); } 

lli power(lli n,lli a){ lli res=1; while(a){ if(a%2) res*=n,a--; else   n*=n,a/=2;} return res;}

lli modpower(lli n,lli a,lli p){ lli res=1; while(a){ if(a%2) res= ((res*n)%p) ,a--; else n=((n*n)%p),a/=2;} return res;}

lli fastprime(lli a){ if (a != 2 && a % 2 == 0 || a < 2) return 0;  for(lli i = 3; i * i <= a; i += 2) if(a % i == 0) return 0; return 1;}  

lli mod_mul_inverse(lli a,lli b) {return modpower(a , b-2, b);}

using namespace std;



template <unsigned int MOD>

struct ModInt {

using uint = unsigned int;

using ull = unsigned long long;

using M = ModInt;

uint v;

ModInt(lli _v = 0) { set_norm(_v % MOD + MOD); }

M& set_norm(uint _v) {  //[0, MOD * 2)->[0, MOD)

v = (_v < MOD) ? _v : _v - MOD;

return *this;

}

explicit operator bool() const { return v != 0; }

M operator+(const M& a) const { return M().set_norm(v + a.v); }

M operator-(const M& a) const { return M().set_norm(v + MOD - a.v); }

M operator*(const M& a) const { return M().set_norm(ull(v) * a.v % MOD); }

M operator/(const M& a) const { return *this * a.inv(); }

M& operator+=(const M& a) { return *this = *this + a; }

M& operator-=(const M& a) { return *this = *this - a; }

M& operator*=(const M& a) { return *this = *this * a; }

M& operator/=(const M& a) { return *this = *this / a; }

M operator-() const { return M() - *this; }

M& operator++(int) { return *this = *this + 1; }

M& operator--(int) { return *this = *this - 1; }

M pow(lli n) const {

if (n < 0) return inv().pow(-n);

M x = *this, res = 1;

while (n) {

if (n & 1) res *= x;

x *= x;

n >>= 1;

}

return res;

}

M inv() const {

lli a = v, b = MOD, p = 1, q = 0, t;

while (b != 0) {

t = a / b;

swap(a -= t * b, b);

swap(p -= t * q, q);

}

return M(p);

}

bool operator==(const M& a) const { return v == a.v; }

bool operator!=(const M& a) const { return v != a.v; }

friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; }

static uint get_mod() { return MOD; }

};

;

using Mint = ModInt<1000000007>;

void solve()

{

    string a;

    cin>>a;

    string b;

    cin>>b;

    string c;

    cin>>c;

    lli n = a.size();

    lli m = b.size();

    vector<vector<lli>>dp(n+5, vector<lli>(m+5,1e14));

    dp[0][0] = 0;

    for(lli i=0;i<n;i++)

    {

        dp[i+1][0] = dp[i][0] + (a[i]!=c[i]);

    }



    for(lli i=0;i<m;i++)

    {

        dp[0][i+1] = dp[0][i] + (b[i]!=c[i]);

    }



    for(lli i=1;i<=n;i++)

    {

        for(lli j=1;j<=m;j++)

        {

            dp[i][j] = min(dp[i-1][j] + (a[i-1]!=c[i+j-1]), dp[i][j-1] + (b[j-1]!=c[i+j-1]));

        }

    }



    cout<<dp[n][m]<<endl;



}

int main()

{

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;

    cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

}