Logo
(追記) (追記ここまで)

32820번 - Covers 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB257504122.527%

문제

You are given two strings $T$ and $P$. Your aim is to create $T$ with $P$. You first begin with an empty string. Then you can do one of three operations shown below.

  • Put $P$ at the end of the current string. This operation costs 0ドル$.
  • Put a character at the end of the current string. This operation costs 1ドル$.
  • Delete characters at the end of the current string and put $P$. This operation costs the number of characters you deleted.

For example, assume that $T = $aabaabaa and $P = $aaba. There are two ways to create $T$ with $P$ as follows, where ε denotes an empty string.

  • εaabaaabaaaabaabaabaabaaabaabaa, or
  • εaabaaabaabaabaaabaabaa.

The former costs four as it first puts $P$ (cost 0ドル$) and four characters (a, b, a, and a, cost 4ドル$). The latter costs two as it first puts $P$ (cost 0ドル$), then deletes one character (a, cost 1ドル$) and puts $P$ (cost 0ドル$), and finally puts a character (a, cost 1ドル$). We choose the latter and we can see that it has the minimum cost.

Given $T$ and $P,ドル write a program which computes the minimum cost to create $T$ with $P$.

입력

Your program is to read from standard input. The input starts with a line containing two integers, $m$ and $n$ (1ドル ≤ m ≤ 100,000円,ドル 1ドル ≤ n ≤ 200,000円$), where $m$ is the length of $P$ and $n$ is that of $T$. The second line contains $P$ and the third line contains $T$. Both $P$ and $T$ are in English lower-case letters.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the minimum cost to create $T$ with $P$.

제한

예제 입력 1

4 8
aaba
aabaabaa

예제 출력 1

2

예제 입력 2

4 8
aaba
ccdccdcc

예제 출력 2

8

예제 입력 3

4 8
abab
abababab

예제 출력 3

0

힌트

출처

ICPC > Regionals > Asia Pacific > Korea > Nationwide Internet Competition > Seoul Nationalwide Internet Competition 2024 C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /