問題一覧 > 通常問題

No.225 文字列変更(medium)

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 270
作問者 : drken1215
お気に入りにしたユーザー ProblemId : 610 / 自分の提出
問題文最終更新日: 2026-06-25 13:42:18
String Modification (medium)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 110 (順位表) の他の問題:

Problem Statement

You are given a string \(S\) of length \(n\) and a string \(T\) of length \(m\). Each character of the strings is one of 'a'–'z'.
Now, you want to convert \(S\) into \(T\) by successively applying any of the following 3 types of operations.
Among all such sequences of operations, consider one with the minimum number of operations, and write a program that outputs that minimum number.

(Operations)
[Change] Choose one character \(S\)[ i ] from \(S\) and change it to any character of your choice from 'a'–'z'.
[Delete] Choose one character \(S\)[ i ] from \(S\) and delete it. It is allowed for the string to become empty as a result of the deletion.
[Insert] Insert any one of the characters 'a'–'z' at any position of your choice in \(S\). In particular, you can also add a character at the beginning or the end of S.

Input

\(n\) \(m\)
\(S\)
\(T\)

The first line contains integers \(n\), \(m\), representing the lengths of the strings \(S\), \(T\), separated by a space.
The following second and third lines contain the strings \(S\), \(T\), respectively.

\(1 \leq n, m \leq 1000\)
\(S\), \(T\) are strings consisting of 'a'–'z'

Output

Output the answer on 1 line.

Sample

Sample 1
Input
9 9
abcdefghi
acdefxhij
Output
3

Delete the 2nd character b
abcedfghi -> acdefghi
Add j at the end
acdefghi -> acdefghij
Change the 6th character g to x
acdefghij -> acdefxhij

Sample 2
Input
3 4
abc
addc
Output
2

Sample 3
Input
14 16
pirikapirirara
poporinapeperuto
Output
10

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。