logo AlgoBeat OnlineJudge
登录 注册

#215309. [SWERC 2024] Phryctoria

内存限制:2048 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Lusius Quietus, one of the generals of Trajan, the Roman emperor, is sending signals to his army using signal towers like the one above, where the fires you lit can be seen from afar.

He wants to send the string describing military manoeuvres. However, sending long messages via fire signals is time-consuming, so Lusius decides to use a shorthand system. To abbreviate the message, Lusius can replace any substring of with the special character *. For example, if is "swerc", then some possible abbreviations are: "swe*" , "*sw*r*" , "swerc" , "*" , etc. Note that * can match the whole string or no character at all, so "*sw*r*" is indeed considered a valid abbreviation of "swerc" even though it’s longer (Lusius is not always clever).

However, there is a problem: the recipient might misinterpret Lusius’s message. If the abbreviation he sends is also a valid abbreviation of the string , which is a word used to signal retreat, it could lead to losing the war.

Help Lusius find the length of the shortest possible abbreviation of that cannot be interpreted as an abbreviation of .

输入格式

The first line contains two integers and , the lengths of the strings and , respectively. The second line contains the string . The third line contains the string .

输出格式

The length of the shortest abbreviation of .

样例

样例输入 1

5 5
swerc
seerc

样例输出 1

3

数据范围与提示

Sample Explanation

A possible solution is “sw*”.

Limits

  • and contain only lowercase English letters.