CF1930I.Counting Is Fun

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a binary†^\dagger pattern pp of length nn.

A binary string qq of the same length nn is called good if for every ii (1≤i≤n1 \leq i \leq n), there exist indices ll and rr such that:

  • 1≤l≤i≤r≤n1 \leq l \leq i \leq r \leq n, and
  • pip_i is a mode‡^\ddagger of the string qlql+1…qrq_lq_{l+1}\ldots q_r.

Count the number of good binary strings modulo 998 244 353998\,244\,353.

†^\dagger A binary string is a string that only consists of characters 0\mathtt{0} and 1\mathtt{1}.

‡^\ddagger Character cc is a mode of string tt of length mm if the number of occurrences of cc in tt is at least ⌈m2⌉\lceil \frac{m}{2} \rceil. For example, 0\mathtt{0} is a mode of 010\mathtt{010}, 1\mathtt{1} is not a mode of 010\mathtt{010}, and both 0\mathtt{0} and 1\mathtt{1} are modes of 011010\mathtt{011010}.

给你一个长度为 nn 的二进制†^\dagger 模式串 pp。

一个长度同样为 nn 的二进制字符串 qq 被称为好串,当且仅当对每个 ii(1≤i≤n1 \leq i \leq n),均存在下标 ll 和 rr,满足:

  • 1≤l≤i≤r≤n1 \leq l \leq i \leq r \leq n,且
  • pip_i 是子串 qlql+1…qrq_l q_{l+1} \ldots q_r 的一个众数‡^\ddagger。

求好串的个数,对 998 244 353998\,244\,353 取模。

†^\dagger 二进制字符串是指仅由字符 0\mathtt{0} 和 1\mathtt{1} 组成的字符串。

‡^\ddagger 字符 cc 是长度为 mm 的字符串 tt 的众数,当且仅当 cc 在 tt 中的出现次数至少为 ⌈m2⌉\lceil \frac{m}{2} \rceil。例如,0\mathtt{0} 是 010\mathtt{010} 的众数,1\mathtt{1} 不是 010\mathtt{010} 的众数,而 0\mathtt{0} 和 1\mathtt{1} 都是 011010\mathtt{011010} 的众数。

输入格式

The first line of input contains a single integer nn (1≤n≤1051 \le n \le 10^5) — the length of the binary string pp.

The second line of input contains a binary string pp of length nn consisting of characters 0 and 1.

输入的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)——即二进制字符串 pp 的长度。

输入的第二行包含一个长度为 nn 的二进制字符串 pp,由字符 0 和 1 组成。

输出格式

Output the number of good strings modulo 998 244 353998\,244\,353.

输出好字符串的数量对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    1
    0

    输出#1

    1
  • 输入#2

    3
    111

    输出#2

    5
  • 输入#3

    4
    1011

    输出#3

    9
  • 输入#4

    6
    110001

    输出#4

    36
  • 输入#5

    12
    111010001111

    输出#5

    2441

说明/提示

In the second example, the good strings are

  • 010\mathtt{010};
  • 011\mathtt{011};
  • 101\mathtt{101};
  • 110\mathtt{110};
  • 111\mathtt{111}.

在第二个例子中,好的字符串有:

  • 010\mathtt{010};
  • 011\mathtt{011};
  • 101\mathtt{101};
  • 110\mathtt{110};
  • 111\mathtt{111}。

输入解题思路,AI测评打分。不知道怎么写?

首页