AtCoder Regular Contest 193 (Div. 1)
B
Broken Wheel
AtCoder
⌀ 2420
原题
← AC →
翻译中…

Problem Statement

翻译中…

You are given a positive integer $N$ and a length-$N$ string $s_0s_1\ldots s_{N-1}$ consisting only of 0 and 1.

翻译中…

Consider a simple undirected graph $G$ with $(N+1)$ vertices numbered $0, 1, 2, \ldots, N$, and the following edges:

翻译中…
  • For each $i = 0, 1, \ldots, N-1$, there is an undirected edge between vertices $i$ and $(i+1)\bmod N$.
  • For each $i = 0, 1, \ldots, N-1$, there is an undirected edge between vertices $i$ and $N$ if and only if $s_i =$ 1.
  • There are no other edges.
翻译中…

Furthermore, create a directed graph $G'$ by assigning a direction to each edge of $G$. That is, for each undirected edge $\lbrace u, v \rbrace$ in $G$, replace it with either a directed edge $(u, v)$ from $u$ to $v$ or a directed edge $(v, u)$ from $v$ to $u$.

翻译中…

For each $i = 0, 1, \ldots, N$, let $d_i$ be the in-degree of vertex $i$ in $G'$. Print the number, modulo $998244353$, of distinct sequences $(d_0, d_1, \ldots, d_N)$ that can be obtained.

翻译中…

Constraints

翻译中…
  • $3 \leq N \leq 10^6$
  • $N$ is an integer.
  • Each $s_i$ is 0 or 1.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
s_0s_1\ldots s_{N-1}

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3
010
Output #1
14
$G$ has four undirected edges: $\lbrace 0, 1 \rbrace, \lbrace 0, 2 \rbrace, \lbrace 1, 2 \rbrace, \lbrace 1, 3 \rbrace$. For example, if we assign directions to each edge as $0 \to 1$, $2 \to 0$, $2 \to 1$, $1 \to 3$, then $(d_0, d_1, d_2, d_3) = (1, 2, 0, 1)$ is obtained. The possible sequences $(d_0, d_1, d_2, d_3)$ are $(0, 1, 2, 1)$, $(0, 2, 1, 1)$, $(0, 2, 2, 0)$, $(0, 3, 1, 0)$, $(1, 0, 2, 1)$, $(1, 1, 1, 1)$, $(1, 1, 2, 0)$, $(1, 2, 0, 1)$, $(1, 2, 1, 0)$, $(1, 3, 0, 0)$, $(2, 0, 1, 1)$, $(2, 1, 0, 1)$, $(2, 1, 1, 0)$, $(2, 2, 0, 0)$, for a total of $14$.
Input #2
20
00001100111010100101
Output #2
261339902
题目信息
题号
arc193_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。