6736.Edit Distance

Time Limit: 1s Memory Limit: 512MB

The edit distance between two strings is the minimum number of operations required to transform one string into the other.

The allowed operations are:

  • Add one character to the string.
  • Remove one character from the string.
  • Replace one character in the string.

For example, the edit distance between LOVE and MOVIE is 2, because you can first replace L with M, and then add I.

Your task is to calculate the edit distance between two strings.

Input Format(From the terminal/stdin)

The first input line has a string that contains $n$ characters between AZ.

The second input line has a string that contains $m$ characters between AZ.

  • $1 \le n,m \le 5000$

Output Format(To the terminal/stdout)

Print one integer: the edit distance between the strings.

Sample Input

Copy
LOVE
MOVIE
    \n
     \n

Sample Output

Copy
2
 \n
Source: CSES, Dynamic Programming, 1639

Submit

请先 登录

© 2025 FAQs