AtCoder Regular Contest 189 (Div. 2)
A
Reversi 2
AtCoder
⌀ 1342
原题
←B →
翻译中…

Problem Statement

翻译中…

There is a grid consisting of $N$ cells numbered $1$ to $N$.

翻译中…

Initially, cell $i$ $(1 \le i \le N)$ has an integer $i \bmod 2$ written in it. You can perform the following operation any number of times, possibly zero:

翻译中…
  • Choose cells $l$ and $r$ ($l+1 < r$) that satisfy the following conditions, and replace each of the integers written in cells $l+1, l+2, \dots, r-1$ with the integer written in cell $l$.
  • The integer written in cell $l$ is equal to the integer written in cell $r$.
    • The integer written in cell $i$ $(l < i < r)$ is different from the integer written in cell $l$.
翻译中…

Find the number, modulo $998244353$, of sequences of operations that result in the integers written in cell $i$ ($1 \leq i \leq N$) being $A_i$.

翻译中…

Two sequences of operations are considered different if and only if their lengths are different or there exists a positive integer $t$ not exceeding the length of the sequences such that the $(l, r)$ chosen in the $t$-th operations differ.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 2 \times 10^5$
  • $0 \leq A_i \leq 1$
翻译中…

Input

翻译中…

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

翻译中…

N
A_1 A_2 \dots A_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
6
1 1 1 1 1 0
Output #1
3
To make the integers written in each cell $i$ equal to $A_i$, for example, you can perform the following operations. (Here, we represent the state of the grid as a sequence $X = (X_1, X_2, \dots, X_N)$.) - Initially, $X = (1, 0, 1, 0, 1, 0)$. - Choose cells $2$ and $4$. $X$ becomes $(1, 0, 0, 0, 1, 0)$. - Choose cells $1$ and $5$. $X$ becomes $(1, 1, 1, 1, 1, 0)$. Besides the above, there are two other sequences of operations that result in the integers written in cell $i$ being $A_i$, so the answer is $3$.
Input #2
10
1 1 1 1 1 0 1 1 1 0
Output #2
9
题目信息
题号
arc189_a
时间限制
2 s
内存限制
1024 MB

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