luogu#P9164. 「INOH」Round 1 - 狂气

「INOH」Round 1 - 狂气

Problem Description

There is an infinite sequence {a}\{a\}. The array index starts from 11. Initially, a1=1a_1 = 1, and all other positions are 00.

There are mm operations:

  1. For all odd ii, set ai+1ai+1+aia_{i+1} \gets a_{i+1} + a_i.
  2. For all even ii, set ai+1ai+1+aia_{i+1} \gets a_{i+1} + a_i.

You need to find the sequence after all operations are completed.

To make output easier, you only need to output the value of $( \displaystyle\prod_{i = 1}^{m} (a_i + 1))\bmod 998244353$.

Input Format

The first line contains a positive integer mm.

The second line contains a string of length mm, representing the operation sequence.

Output Format

One line, representing the value of $( \displaystyle\prod_{i = 1}^{m} (a_i + 1)) \bmod 998244353$.

5
11221
200
13
1122121212212
400201782

Hint

Sample 1 Explanation

After 55 operations, the first five terms of the sequence are:
a1=1a_1 = 1, a2=3a_2 = 3, a3=4a_3 = 4, a4=4a_4 = 4, a5=0a_5 = 0.

This problem uses bundled testdata.

  • Subtask 0 (10 pts): 1m10001 \le m \le 1000.
  • Subtask 1 (20 pts): the operation sequence is of the form 121212\tt121212\dots.
  • Subtask 2 (20 pts): the operation sequence is generated randomly.
  • Subtask 3 (50 pts): no special constraints.

For 100%100\% of the testdata, 1m2×1051 \le m \le 2 \times 10^5.

Please pay attention to the impact of constant factors on runtime efficiency.

Translated by ChatGPT 5