QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#10565. Twin Friends

Statistics

你结识了两位双胞胎朋友。双胞胎中姐姐的名字为 $A$,由 $N$ 个字符组成;妹妹的名字为 $B$,由 $M$ 个字符组成。已知 $N \le M$。

你想为她们每人取一个昵称。对于姐姐,你想选取 $A$ 的任意一个排列作为昵称。对于妹妹,你想从 $B$ 的任意一个排列中恰好删去 $M - N$ 个字符。记姐姐和妹妹的昵称分别为 $A'$ 和 $B'$。

你希望这些昵称满足以下要求:对于每个满足 $1 \le i \le N$ 的 $i$,$B'_i$ 必须等于 $A'_i$ 或者在字母表中紧随 $A'_i$ 之后的字母(如果存在这样的字母)。

请计算满足要求的不同昵称对 $(A', B')$ 的数量。如果两个昵称对中至少有一个昵称不同,则认为这两个昵称对不同。由于结果可能很大,请输出对 $998\,244\,353$ 取模后的结果。

输入格式

第一行包含两个整数 $N$ 和 $M$ ($1 \le N \le M \le 200\,000$)。 第二行包含一个长度为 $N$ 的字符串 $A$。 第三行包含一个长度为 $M$ 的字符串 $B$。 所有字符串仅由大写字母组成。

输出格式

输出一个整数,表示满足要求的不同昵称对 $(A', B')$ 的数量,对 $998\,244\,353$ 取模。

样例

输入 1

3 4
AMA
ANAB

输出 1

9

说明 1

这 9 对昵称为: (AAM, AAN), (AAM, ABN), (AAM, BAN), (AMA, ANA), (AMA, ANB), (AMA, BNA), (MAA, NAA), (MAA, NAB), 以及 * (MAA, NBA)。

输入 2

5 8
BINUS
BINANUSA

输出 2

120

说明 2

这 120 对昵称即所有满足 $A'$ 是 BINUS 的排列且 $B' = A'$ 的对。

输入 3

15 30
BINUSUNIVERSITY
BINUSANTARAUNIVERSITYJAKARTA

输出 3

151362308

输入 4

4 4
UDIN
ASEP

输出 4

0

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.