Reversi 2

AtCoder
IDarc189_a
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
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
API Response (JSON)
{
  "problem": {
    "name": "Reversi 2",
    "description": {
      "content": "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",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc189_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a grid consisting of $N$ cells numbered $1$ to $N$.\nInitially, 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...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments