CF2187D.Cool Problem

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are two integer constants xx and yy.

For a binary∗^{\text{∗}} string rr of length nn, we define its generating array as an array c=[c0,c1,…,cn]c=[c_0,c_1,\ldots,c_n] such that c0=0c_0=0, and for each 1≤i≤n1 \le i \le n:

  • If ri=0r_i=\mathtt{0}, then ci=x+ci−1c_i=x+c_{i-1};
  • If ri=1r_i=\mathtt{1}, then ci=y−ci−1c_i=y-c_{i-1}.

Additionally, we define f(r)=∑i=1ncif(r)=\sum\limits_{i=1}^n c_i.

You are given an incomplete binary string ss of length nn, where some characters in it are missing, represented by ?\mathtt{?}. An integer kk is called cool if and only if there exists a way to replace each ?\mathtt{?} in ss with either 0\mathtt{0} or 1\mathtt{1}, such that f(s)=kf(s)=k.

Your task is to calculate the sum of all cool integers, modulo 998 244 353998\,244\,353.

∗^{\text{∗}}A binary string is a string where each character is either 0\mathtt{0} or 1\mathtt{1}.

存在两个整数常量 xx 和 yy。

对于一个长度为 nn 的二进制∗^{\text{∗}}字符串 rr,我们定义其生成数组为一个数组 c=[c0,c1,…,cn]c=[c_0,c_1,\ldots,c_n],其中 c0=0c_0=0,且对每个 1≤i≤n1 \le i \le n:

  • 若 ri=0r_i=\mathtt{0},则 ci=x+ci−1c_i=x+c_{i-1};
  • 若 ri=1r_i=\mathtt{1},则 ci=y−ci−1c_i=y-c_{i-1}。

此外,我们定义 f(r)=∑i=1ncif(r)=\sum\limits_{i=1}^n c_i。

给定一个长度为 nn 的不完整二进制字符串 ss,其中某些字符缺失,用 ?\mathtt{?} 表示。一个整数 kk 被称为“酷”的,当且仅当存在一种方式,将 ss 中每个 ?\mathtt{?} 替换为 0\mathtt{0} 或 1\mathtt{1},使得 f(s)=kf(s)=k。

你的任务是计算所有“酷”整数的和,并对 998 244 353998\,244\,353 取模。

∗^{\text{∗}}二进制字符串是指每个字符均为 0\mathtt{0} 或 1\mathtt{1} 的字符串。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains three integers nn, xx, and yy (1≤n≤1051 \le n \le 10^5, 1≤x,y≤1061 \le x,y \le 10^6) — the length of ss and the given constants.

The second line contains the incomplete binary string ss of length nn (si∈0,1,?s_i \in {\mathtt{0}, \mathtt{1}, \mathtt{?}}).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、xx 和 yy(1≤n≤1051 \le n \le 10^5,1≤x,y≤1061 \le x,y \le 10^6)——分别表示字符串 ss 的长度以及给定的常数。

第二行包含一个长度为 nn 的不完整二进制字符串 ss(其中 si∈{0,1,?}s_i \in \{\mathtt{0}, \mathtt{1}, \mathtt{?}\})。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For each test case, output a single integer — the sum of all cool integers modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一个整数——所有酷整数的和对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    4
    1 1 2
    0
    1 1 2
    ?
    3 7 5
    ?0?
    7 114514 191981
    ?1?????

    输出#1

    1
    3
    100
    8039591

说明/提示

In the first test case, the string ss has already been determined, and its generating array is [0,1][0, 1]. Thus, f(s)=1f(s)=1, and the only cool integer is 11.

In the third test case, there are four ways to complete the string ss:

ss

Generating array

f(s)f(s)

000\mathtt{000}

[0,7,14,21][0, 7, 14, 21]

4242

001\mathtt{001}

[0,7,14,−9][0, 7, 14, -9]

1212

100\mathtt{100}

[0,5,12,19][0, 5, 12, 19]

3636

101\mathtt{101}

[0,5,12,−7][0, 5, 12, -7]

1010

Thus, the sum of all cool integers is 42+12+36+10=10042+12+36+10=100.

在第一个测试用例中,字符串 ss 已经被确定,其生成数组为 [0,1][0, 1]。因此,f(s)=1f(s)=1,唯一的“酷整数”是 11。

在第三个测试用例中,共有四种方式补全字符串 ss:

ss

生成数组

f(s)f(s)

000\mathtt{000}

[0,7,14,21][0, 7, 14, 21]

4242

001\mathtt{001}

[0,7,14,−9][0, 7, 14, -9]

1212

100\mathtt{100}

[0,5,12,19][0, 5, 12, 19]

3636

101\mathtt{101}

[0,5,12,−7][0, 5, 12, -7]

1010

因此,所有“酷整数”的和为 42+12+36+10=10042+12+36+10=100。

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

首页