Problem:
Edit Distance (Levenshtein Distance)

Find the edit distance between given two words s1 and s2.

The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations:

insertion: Insert a character at a particular position.

deletion: Delete a character at a particular position.

substitution: Change the character at a particular position to a different character

Input

s1
s2

Two words s1 and s2 are given in the first line and the second line respectively. The words will consist of lower case characters.

Output

Print the edit distance in a line.

Constraints

1 ≤ length of s1 ≤ 1000

1 ≤ length of s2 ≤ 1000

Sample Input 1

acac
acm

Sample Output 1

2

Sample Input 2

icpc
icpc

Sample Output 2

0

Solution in C++14 (judge verdict: Accepted)

#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string a, b;
  cin >> a >> b;
  ll al = a.size(), bl = b.size();
  vector<vector<ll>> dp(al + 1, vector<ll>(bl + 1, INF));
  dp.at(0).at(0) = 0;
  for (ll i = 0; i < al; ++i) {
    for (ll j = 0; j < bl; ++j) {
      if (a.at(i) == b.at(j)) {
        dp.at(i + 1).at(j + 1) = min(dp.at(i + 1).at(j + 1), dp.at(i).at(j));
      }
      //削除・挿入
      dp.at(i + 1).at(j) = min(dp.at(i + 1).at(j), dp.at(i).at(j) + 1);
      dp.at(i).at(j + 1) = min(dp.at(i).at(j + 1), dp.at(i).at(j) + 1);
      //変更
      dp.at(i + 1).at(j + 1) = min(dp.at(i + 1).at(j + 1), dp.at(i).at(j) + 1);

      dp.at(al).at(j + 1) = min(dp.at(al).at(j + 1), dp.at(al).at(j) + 1);
    }
    dp.at(i + 1).at(bl) = min(dp.at(i + 1).at(bl), dp.at(i).at(bl) + 1);
  }
  cout << dp.at(al).at(bl) << "\n";
  // for (ll i = 0; i <= al; ++i) {
  //   for (ll j = 0; j <= bl; ++j) {
  //     cout << dp.at(i).at(j) << " ";
  //   }
  //   cout << "\n";
  // }
}