CF1336C.Kaavi and Magic Spell

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Kaavi, the mysterious fortune teller, deeply believes that one's fate is inevitable and unavoidable. Of course, she makes her living by predicting others' future. While doing divination, Kaavi believes that magic spells can provide great power for her to see the future.

Kaavi has a string TT of length mm and all the strings with the prefix TT are magic spells. Kaavi also has a string SS of length nn and an empty string AA.

During the divination, Kaavi needs to perform a sequence of operations. There are two different operations:

  • Delete the first character of SS and add it at the front of AA.
  • Delete the first character of SS and add it at the back of AA.

Kaavi can perform no more than nn operations. To finish the divination, she wants to know the number of different operation sequences to make AA a magic spell (i.e. with the prefix TT). As her assistant, can you help her? The answer might be huge, so Kaavi only needs to know the answer modulo 998 244 353998\,244\,353.

Two operation sequences are considered different if they are different in length or there exists an ii that their ii-th operation is different.

A substring is a contiguous sequence of characters within a string. A prefix of a string SS is a substring of SS that occurs at the beginning of SS.

神秘的占卜师凯薇深信,人的命运是注定且不可改变的。当然,她靠预测他人的未来谋生。在占卜过程中,凯薇相信魔法咒语能赋予她强大的力量,从而窥见未来。

凯薇拥有一个长度为 mm 的字符串 TT,所有以 TT 为前缀的字符串均被视为魔法咒语。此外,她还有一个长度为 nn 的字符串 SS 和一个空字符串 AA。

在占卜过程中,凯薇需执行一系列操作。共有两种不同的操作:

  • 删除 SS 的首字符,并将其添加到 AA 的前端;
  • 删除 SS 的首字符,并将其添加到 AA 的尾端。

凯薇最多可执行 nn 次操作。为了完成占卜,她想知道:有多少种不同的操作序列,能使最终得到的 AA 成为一个魔法咒语(即 AA 以 TT 为前缀)?作为她的助手,你能帮她解决这个问题吗?答案可能非常大,因此凯薇只需要知道答案对 998 244 353998\,244\,353 取模的结果。

若两个操作序列长度不同,或存在某个位置 ii 使得它们的第 ii 次操作不同,则认为这两个操作序列不同。

子串是指字符串中连续的一段字符序列。字符串 SS 的前缀是指出现在 SS 开头位置的子串。

输入格式

The first line contains a string SS of length nn (1≤n≤30001 \leq n \leq 3000).

The second line contains a string TT of length mm (1≤m≤n1 \leq m \leq n).

Both strings contain only lowercase Latin letters.

第一行包含一个长度为 nn 的字符串 SS(1≤n≤30001 \leq n \leq 3000)。

第二行包含一个长度为 mm 的字符串 TT(1≤m≤n1 \leq m \leq n)。

两个字符串均仅由小写拉丁字母组成。

输出格式

The output contains only one integer — the answer modulo 998 244 353998\,244\,353.

输出仅包含一个整数——答案对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    abab
    ba

    输出#1

    12
  • 输入#2

    defineintlonglong
    signedmain

    输出#2

    0
  • 输入#3

    rotator
    rotator

    输出#3

    4
  • 输入#4

    cacdcdbbbb
    bdcaccdbbb

    输出#4

    24

说明/提示

The first test:

The red ones are the magic spells. In the first operation, Kaavi can either add the first character "a" at the front or the back of AA, although the results are the same, they are considered as different operations. So the answer is 6×2=126\times2=12.

第一次测试:

红色部分为魔法咒语。在第一次操作中,Kaavi 可以将第一个字符 “a” 添加到 AA 的前端或后端;尽管两种操作的结果相同,但仍被视为不同的操作。因此答案为 6×2=126\times2=12。

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

首页