A11317 | Counting Is Fun
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a binary $^\dagger$ pattern $p$ of length $n$ .
A binary string $q$ of the same length $n$ is called good if for every $i$ ( $1 \leq i \leq n$ ), there exist indices $l$ and $r$ such that:
- $1 \leq l \leq i \leq r \leq n$ , and
- $p_i$ is a mode $^\ddagger$ of the string $q_lq_{l+1}\ldots q_r$ .
Count the number of good binary strings modulo $998\,244\,353$ .
$^\dagger$ A binary string is a string that only consists of characters $\mathtt{0}$ and $\mathtt{1}$ .
$^\ddagger$ Character $c$ is a mode of string $t$ of length $m$ if the number of occurrences of $c$ in $t$ is at least $\lceil \frac{m}{2} \rceil$ . For example, $\mathtt{0}$ is a mode of $\mathtt{010}$ , $\mathtt{1}$ is not a mode of $\mathtt{010}$ , and both $\mathtt{0}$ and $\mathtt{1}$ are modes of $\mathtt{011010}$ .
A binary string $q$ of the same length $n$ is called good if for every $i$ ( $1 \leq i \leq n$ ), there exist indices $l$ and $r$ such that:
- $1 \leq l \leq i \leq r \leq n$ , and
- $p_i$ is a mode $^\ddagger$ of the string $q_lq_{l+1}\ldots q_r$ .
Count the number of good binary strings modulo $998\,244\,353$ .
$^\dagger$ A binary string is a string that only consists of characters $\mathtt{0}$ and $\mathtt{1}$ .
$^\ddagger$ Character $c$ is a mode of string $t$ of length $m$ if the number of occurrences of $c$ in $t$ is at least $\lceil \frac{m}{2} \rceil$ . For example, $\mathtt{0}$ is a mode of $\mathtt{010}$ , $\mathtt{1}$ is not a mode of $\mathtt{010}$ , and both $\mathtt{0}$ and $\mathtt{1}$ are modes of $\mathtt{011010}$ .
输入格式
The first line of input contains a single integer $n$ ( $1 \le n \le 10^5$ ) — the length of the binary string $p$ .
The second line of input contains a binary string $p$ of length $n$ consisting of characters 0 and 1.
The second line of input contains a binary string $p$ of length $n$ consisting of characters 0 and 1.
输出格式
Output the number of good strings modulo $998\,244\,353$ .
输入输出样例
输入 #1
1 0
输出 #1
1
输入 #2
3 111
输出 #2
5
输入 #3
4 1011
输出 #3
9
输入 #4
6 110001
输出 #4
36
输入 #5
12 111010001111
输出 #5
2441
In the second example, the good strings are
- $\mathtt{010}$ ;
- $\mathtt{011}$ ;
- $\mathtt{101}$ ;
- $\mathtt{110}$ ;
- $\mathtt{111}$ .
- $\mathtt{010}$ ;
- $\mathtt{011}$ ;
- $\mathtt{101}$ ;
- $\mathtt{110}$ ;
- $\mathtt{111}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted