Covers

시간 제한1초메모리 제한2048 MB

요약
빈 문자열에서 시작해 패턴 P를 붙이는 연산은 무료, 문자 하나 추가와 끝 문자 삭제는 비용이 들 때 T를 만드는 최소 비용을 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 문자열 매칭, 그리디
정답자
아직 제출이 없습니다

문제

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

  • Put PP at the end of the current string. This operation costs 00.
  • Put a character at the end of the current string. This operation costs 11.
  • Delete characters at the end of the current string and put PP. This operation costs the number of characters you deleted.

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

  • ε → aaba → aabaa → aabaab → aabaaba → aabaabaa, or
  • ε → aaba → aab → aabaaba → aabaabaa.

The former costs four as it first puts PP (cost 00) and four characters (a, b, a, and a, cost 44). The latter costs two as it first puts PP (cost 00), then deletes one character (a, cost 11) and puts PP (cost 00), and finally puts a character (a, cost 11). We choose the latter and we can see that it has the minimum cost.

Given TT and PP, write a program which computes the minimum cost to create TT with PP.

입력

Your program is to read from standard input. The input starts with a line containing two integers, mm and nn (1≤m≤100,0001 ≤ m ≤ 100\\,000, 1≤n≤200,0001 ≤ n ≤ 200\\,000), where mm is the length of PP and nn is that of TT. The second line contains PP and the third line contains TT. Both PP and TT 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 TT with PP.

예제3

  1. 예제 1

    입력
    4 8
    aaba
    aabaabaa
    
    예상 출력
    2
    
  2. 예제 2

    입력
    4 8
    aaba
    ccdccdcc
    
    예상 출력
    8
    
  3. 예제 3

    입력
    4 8
    abab
    abababab
    
    예상 출력
    0