QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#12221. 知识

統計

你有一个由小写英文字母 “a” 和 “b” 组成的字符串 $s$。

你可以按任意顺序执行零次或多次以下操作:

  • 从字符串的任意位置删除 “aa”。
  • 从字符串的任意位置删除 “bbb”。
  • 从字符串的任意位置删除 “ababab”。
  • 在字符串的任意位置添加 “aa”。
  • 在字符串的任意位置添加 “bbb”。
  • 在字符串的任意位置添加 “ababab”。

你的目标是计算通过上述操作可以得到的长度为 $x$ 的字符串的数量。由于答案可能非常大,请将其对 $998\,244\,353$ 取模。

输入格式

第一行包含一个整数 $n$:字符串的长度 ($1 \le n \le 300\,000$)。 第二行包含一个长度为 $n$ 的字符串 $s$,由小写英文字母 “a” 和 “b” 组成。 第三行包含一个整数 $x$ ($0 \le x \le 10^9$),即你需要得到的字符串长度。

输出格式

输出一个整数:通过上述操作可以从字符串 $s$ 得到的长度为 $x$ 的字符串的数量,结果对 $998\,244\,353$ 取模。

样例

样例输入 1

6
ababab
3

样例输出 1

1

样例输入 2

3
bbb
2

样例输出 2

1

样例输入 3

5
babab
35

样例输出 3

866826000

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#356EditorialOpen题解jiangly2025-12-14 07:16:09View

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.