#P17133. [ICPC 2025 Shanghai R] Yet another 01 problem

    ID: 19470 远端评测题 10000ms 1024MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>2025多项式上海区间 DP容斥原理ICPC

[ICPC 2025 Shanghai R] Yet another 01 problem

Problem Description

Yana, Mino, White, and Huzz are best friends.

Mino has been feeling confused lately. Obsessed with his past failures in OI, he has been struggling to plan his future while managing his busy school schedule. His three friends suggested he evaluate the importance of his tasks and prioritize them.

Assume there are nn different tasks numbered from 11 to nn. Each time, Huzz selects two adjacent tasks, White compares them, and Yana merges them into a single task. Mino is surprised to find that this process accidentally forms a segment tree, which does not necessarily split in the middle. More precisely, it forms a tree with 2n12n - 1 nodes, where every subtree corresponds to a contiguous segment. Note that all nn tasks are leaves, while the other n1n - 1 nodes each have two children. These nodes, which result from comparisons, define the values of the edges to their children: 00 for the smaller one and 11 for the larger one.

Mino is very fond of calculations. He defines the weight of each task as the XOR sum of the edges along the path from the task to the root. He wonders: if the weights are given, how many ways are there to construct such trees and compare the children?

Once again, Mino is not skilled in OI, which is why he has turned to you for help. To simplify the problem, you only need to find the answer modulo 998,244,353998,244,353.

Input Format

The first line of the input contains a positive integer nn (1n2500001 \le n \le 250000), the number of tasks.

The second line contains a binary string SS of length nn, where SiS_i represents the Bitwise-XOR of all values on the edges from task ii to the root.

Output Format

Print an integer, the answer modulo 998,244,353998,244,353.

4
0101
6

Hint

There are 66 ways to construct the tree and compare the children:

:::align{center} :::