CF1906H.Twin Friends

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You meet two new friends who are twins. The name of the elder twin is AA, which consists of NN characters. While the name of the younger twin is BB, which consists of MM characters. It is known that N≤MN \leq M.

You want to call each of them with a nickname. For the elder twin, you want to pick any permutation of AA as the nickname. For the younger twin, you want to remove exactly M−NM - N characters from any permutation of BB. Denote the nicknames of the elder twin and the younger twin as A′A' and B′B', respectively.

You want the nicknames to satisfy the following requirement. For each ii that satisfies 1≤i≤N1 \leq i \leq N, Bi′B'_i must be equal to either Ai′A'_i or the next letter that follows alphabetically after Ai′A'_i (if such a next letter exists).

Determine the number of different pairs of nicknames (A′,B′)(A', B') that satisfy the requirement. Two pairs of nicknames are considered different if at least one of the nicknames are different. As the result might be large, find the answer modulo 998 244 353998\,244\,353.

你遇到了两位新朋友,她们是一对双胞胎。姐姐的名字为 AA,由 NN 个字符组成;妹妹的名字为 BB,由 MM 个字符组成。已知 N≤MN \leq M。

你想分别为她们取一个昵称。对于姐姐,你想从 AA 的任意一个排列中选取作为昵称;对于妹妹,你想从 BB 的任意一个排列中恰好删去 M−NM - N 个字符,从而得到她的昵称。分别记姐姐和妹妹的昵称为 A′A' 和 B′B'。

你希望这些昵称满足如下要求:对每个满足 1≤i≤N1 \leq i \leq N 的下标 ii,Bi′B'_i 必须等于 Ai′A'_i,或等于紧接在 Ai′A'_i 之后的、按字母表顺序的下一个字母(如果该下一个字母存在)。

请计算满足上述要求的不同昵称对 (A′,B′)(A', B') 的数量。若两个昵称对中至少有一个昵称不同,则认为它们是不同的。由于答案可能很大,请将结果对 998 244 353998\,244\,353 取模。

输入格式

The first line consists of two integers NN MM (1≤N≤M≤200 0001 \leq N \leq M \leq 200\,000).

The second line consists of a string AA of length NN.

The third line consists of a string BB of length MM.

All strings consist of only upper-case letters.

第一行包含两个整数 NN 和 MM(1≤N≤M≤200 0001 \leq N \leq M \leq 200\,000)。

第二行包含一个长度为 NN 的字符串 AA。

第三行包含一个长度为 MM 的字符串 BB。

所有字符串仅由大写字母组成。

输出格式

Output a single integer representing number of different pairs (A′,B′)(A', B') that satisfy the requirement, modulo 998 244 353998\,244\,353.

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

输入输出样例

  • 输入#1

    3 4
    AMA
    ANAB

    输出#1

    9
  • 输入#2

    5 8
    BINUS
    BINANUSA

    输出#2

    120
  • 输入#3

    15 30
    BINUSUNIVERSITY
    BINANUSANTARAUNIVERSITYJAKARTA

    输出#3

    151362308
  • 输入#4

    4 4
    UDIN
    ASEP

    输出#4

    0

说明/提示

Explanation for the sample input/output #1

The 99 pairs are:

  • (AAM, AAN),
  • (AAM, ABN),
  • (AAM, BAN),
  • (AMA, ANA),
  • (AMA, ANB),
  • (AMA, BNA),
  • (MAA, NAA),
  • (MAA, NAB), and
  • (MAA, NBA).

Explanation for the sample input/output #2

The 120120 pairs are the pairs where A′A' is a permutation of BINUS and B′=A′B' = A'.

样例输入/输出 #1 的解释

这 9 对字符串为:

  • (AAM, AAN),
  • (AAM, ABN),
  • (AAM, BAN),
  • (AMA, ANA),
  • (AMA, ANB),
  • (AMA, BNA),
  • (MAA, NAA),
  • (MAA, NAB),
  • (MAA, NBA)。

样例输入/输出 #2 的解释

这 120 对字符串是所有满足 A′A' 是 BINUS 的一个排列、且 B′=A′B' = A' 的字符串对。

输入解题思路,AI测评打分。不知道怎么写?

首页