QOJ.ac

QOJ

时间限制: 1 s 内存限制: 2048 MB 总分: 100

#15697. Phryctoria

统计

罗马皇帝图拉真麾下的将军之一卢修斯·奎图斯(Lusius Quietus)正在使用类似于上图的信号塔向他的军队发送信号,在那里点燃的烽火可以从远处看到。

他想发送一个描述军事行动的字符串 $S$。然而,通过烽火信号发送长消息非常耗时,因此卢修斯决定使用一种速记系统。为了缩写消息,卢修斯可以将 $S$ 的任意子串替换为特殊字符 *。例如,如果 $S$ 是 "swerc",那么一些可能的缩写包括:"swe"、"swr"、"swerc"、"" 等。注意,`` 可以匹配整个字符串或不匹配任何字符,因此即使 "swr*" 更长,它确实也被视为 "swerc" 的有效缩写(卢修斯并不总是那么聪明)。

然而,存在一个问题:接收者可能会误解卢修斯的消息。如果他发送的缩写同时也是字符串 $T$(一个用于表示撤退的单词)的有效缩写,这可能会导致输掉战争。

帮助卢修斯找到 $S$ 的最短可能缩写的长度,使得该缩写不能被解释为 $T$ 的缩写。

输入格式

第一行包含两个整数 $N$ 和 $M$,分别表示字符串 $S$ 和 $T$ 的长度。

第二行包含字符串 $S$。

第三行包含字符串 $T$。

输出格式

输出 $S$ 的最短缩写的长度。

数据范围

  • $1 \le N \le 500$。
  • $1 \le M \le 500$。
  • $S \ne T$。
  • $S$ 和 $T$ 仅包含英文小写字母。

样例

输入样例 1

5 5
swerc
seerc

输出样例 1

3

说明

一个可能的解是 "sw*"。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.