A13441 | Kaavi and Magic Spell
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $T$ of length $m$ and all the strings with the prefix $T$ are magic spells. Kaavi also has a string $S$ of length $n$ and an empty string $A$ .
During the divination, Kaavi needs to perform a sequence of operations. There are two different operations:
- Delete the first character of $S$ and add it at the front of $A$ .
- Delete the first character of $S$ and add it at the back of $A$ .
Kaavi can perform no more than $n$ operations. To finish the divination, she wants to know the number of different operation sequences to make $A$ a magic spell (i.e. with the prefix $T$ ). As her assistant, can you help her? The answer might be huge, so Kaavi only needs to know the answer modulo $998\,244\,353$ .
Two operation sequences are considered different if they are different in length or there exists an $i$ that their $i$ -th operation is different.
A substring is a contiguous sequence of characters within a string. A prefix of a string $S$ is a substring of $S$ that occurs at the beginning of $S$ .

Kaavi has a string $T$ of length $m$ and all the strings with the prefix $T$ are magic spells. Kaavi also has a string $S$ of length $n$ and an empty string $A$ .
During the divination, Kaavi needs to perform a sequence of operations. There are two different operations:
- Delete the first character of $S$ and add it at the front of $A$ .
- Delete the first character of $S$ and add it at the back of $A$ .
Kaavi can perform no more than $n$ operations. To finish the divination, she wants to know the number of different operation sequences to make $A$ a magic spell (i.e. with the prefix $T$ ). As her assistant, can you help her? The answer might be huge, so Kaavi only needs to know the answer modulo $998\,244\,353$ .
Two operation sequences are considered different if they are different in length or there exists an $i$ that their $i$ -th operation is different.
A substring is a contiguous sequence of characters within a string. A prefix of a string $S$ is a substring of $S$ that occurs at the beginning of $S$ .
输入格式
The first line contains a string $S$ of length $n$ ( $1 \leq n \leq 3000$ ).
The second line contains a string $T$ of length $m$ ( $1 \leq m \leq n$ ).
Both strings contain only lowercase Latin letters.
The second line contains a string $T$ of length $m$ ( $1 \leq m \leq n$ ).
Both strings contain only lowercase Latin letters.
输出格式
The output contains only one integer — the answer modulo $998\,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 $A$ , although the results are the same, they are considered as different operations. So the answer is $6\times2=12$ .

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 $A$ , although the results are the same, they are considered as different operations. So the answer is $6\times2=12$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted