CF2187D.Cool Problem
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are two integer constants x and y.
For a binary∗ string r of length n, we define its generating array as an array c=[c0,c1,…,cn] such that c0=0, and for each 1≤i≤n:
- If ri=0, then ci=x+ci−1;
- If ri=1, then ci=y−ci−1.
Additionally, we define f(r)=i=1∑nci.
You are given an incomplete binary string s of length n, where some characters in it are missing, represented by ?. An integer k is called cool if and only if there exists a way to replace each ? in s with either 0 or 1, such that f(s)=k.
Your task is to calculate the sum of all cool integers, modulo 998244353.
∗A binary string is a string where each character is either 0 or 1.
存在两个整数常量 x 和 y。
对于一个长度为 n 的二进制∗字符串 r,我们定义其生成数组为一个数组 c=[c0,c1,…,cn],其中 c0=0,且对每个 1≤i≤n:
- 若 ri=0,则 ci=x+ci−1;
- 若 ri=1,则 ci=y−ci−1。
此外,我们定义 f(r)=i=1∑nci。
给定一个长度为 n 的不完整二进制字符串 s,其中某些字符缺失,用 ? 表示。一个整数 k 被称为“酷”的,当且仅当存在一种方式,将 s 中每个 ? 替换为 0 或 1,使得 f(s)=k。
你的任务是计算所有“酷”整数的和,并对 998244353 取模。
∗二进制字符串是指每个字符均为 0 或 1 的字符串。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains three integers n, x, and y (1≤n≤105, 1≤x,y≤106) — the length of s and the given constants.
The second line contains the incomplete binary string s of length n (si∈0,1,?).
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含三个整数 n、x 和 y(1≤n≤105,1≤x,y≤106)——分别表示字符串 s 的长度以及给定的常数。
第二行包含一个长度为 n 的不完整二进制字符串 s(其中 si∈{0,1,?})。
保证所有测试用例的 n 之和不超过 105。
输出格式
For each test case, output a single integer — the sum of all cool integers modulo 998244353.
对于每个测试用例,输出一个整数——所有酷整数的和对 998244353 取模的结果。
输入输出样例
输入#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 s has already been determined, and its generating array is [0,1]. Thus, f(s)=1, and the only cool integer is 1.
In the third test case, there are four ways to complete the string s:
s
Generating array
f(s)
000
[0,7,14,21]
42
001
[0,7,14,−9]
12
100
[0,5,12,19]
36
101
[0,5,12,−7]
10
Thus, the sum of all cool integers is 42+12+36+10=100.
在第一个测试用例中,字符串 s 已经被确定,其生成数组为 [0,1]。因此,f(s)=1,唯一的“酷整数”是 1。
在第三个测试用例中,共有四种方式补全字符串 s:
s
生成数组
f(s)
000
[0,7,14,21]
42
001
[0,7,14,−9]
12
100
[0,5,12,19]
36
101
[0,5,12,−7]
10
因此,所有“酷整数”的和为 42+12+36+10=100。
输入解题思路,AI测评打分。不知道怎么写?