Link to this code:
https://cses.fi/paste/e40f7b305c60a4c8decb14/#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define in(a) \
for (auto &x : a) \
cin >> x;
#define out(a) \
for (auto x : a) \
cout << x << " ";
#define pb push_back
#define ll long long
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
void solve() {
string s;
string t;
cin >> s >> t;
int n = s.size();
int m = t.size();
vector<vector<int>> dp(n + 1, vector<int>(m + 1, INT_MAX));
for (int i = 0; i < n; i++) {
dp[i][0] = i;
}
for (int j = 0; j < m; j++) {
dp[0][j] = j;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1];
} else {
dp[i][j] = min({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]}) + 1;
}
}
}
cout << dp[n][m] << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}