CF2223F.Zhily and Colorful Strings
NOI/NOI+/CTSC
通过率:0%
时间限制:7.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Since Jily's first birthday, Zhily has given him a colored string as a gift each year, and each year's gift has been different from all previous ones. This year, Jily was amazed to discover that he has received every possible distinct gift!
We call a colored string that meets the following conditions valid:
- It consists of m types of characters, with exactly ni characters of the i-th type;
- Each character of the i-th type is colored with one of ci colors;
- The string can be reduced to an empty string by repeatedly deleting di consecutive characters of the i-th type that share the same color.
Calculate the number of all valid colored strings, modulo 998244353.
Two colored strings are considered different if they differ in at least one position (either in character type or in color).
自从吉莉一岁生日起,芝莉每年都会送他一根彩色字符串作为礼物,且每年的礼物都与之前所有礼物不同。今年,吉莉惊讶地发现,他已收齐了所有可能的、互不相同的礼物!
我们称满足以下条件的彩色字符串为有效字符串:
- 它由 m 种字符类型组成,其中第 i 种类型恰好出现 ni 次;
- 第 i 种类型的每个字符可被染上 ci 种颜色之一;
- 该字符串可通过重复执行如下操作缩减为空字符串:每次删除 di 个连续的、同属第 i 种类型、且颜色相同的字符。
请计算所有有效彩色字符串的总数,结果对 998244353 取模。
若两个彩色字符串在至少一个位置上不同(字符类型不同,或颜色不同),则视为不同的字符串。
输入格式
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 a single integer m (1≤m≤2⋅105) — the number of types.
The i-th of the next m lines contains ni,ci,di (1≤ci<998244353,1≤ni,di≤108) — the total count of characters of the i-th type, the number of colors for this type, and the required reduction length, respectively.
It is guaranteed that the sum of ⌈dini⌉ over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 m(1≤m≤2⋅105)—— 表示字符类型的种类数。
接下来的 m 行中,第 i 行包含三个整数 ni,ci,di(1≤ci<998244353, 1≤ni,di≤108)—— 分别表示第 i 种类型字符的总数、该类型的可用颜色数以及所需缩减长度。
保证所有测试用例中 ⌈dini⌉ 的总和不超过 2⋅105。
输出格式
For each test case, output one integer in one line, representing the number of valid colored strings, modulo 998244353.
对于每个测试用例,在一行中输出一个整数,表示合法的染色字符串的数量,对 998244353 取模。
输入输出样例
输入#1
3 2 2 1 1 1 2 1 2 2 2 2 2 1 2 2 6 2 3 5 3 2
输出#1
6 8 0
说明/提示
For the examples, let's number all the colors by 1,2,…,∑j=1mcj. Where the colors 1+∑j=1i−1cj,…,∑j=1icj are of the i-th type. Below, the color 1,2,3 are colored red, blue, and green, respectively.
For the first test case, the valid strings are:
- [1,1,2]
- [1,1,3]
- [1,2,1]
- [1,3,1]
- [2,1,1]
- [3,1,1]
For any of these strings, we can first remove the only 2 or 3, and then remove the 2 consecutive 1s.
For the second test case, the valid strings are:
- [1,1,3,3]
- [1,3,3,1]
- [2,2,3,3]
- [2,3,3,2]
- [3,1,1,3]
- [3,2,2,3]
- [3,3,1,1]
- [3,3,2,2]
For the third test case, it can be easily seen that there are no valid strings.
对于示例,我们将所有颜色编号为 1,2,…,∑j=1mcj,其中颜色 1+∑j=1i−1cj,…,∑j=1icj 属于第 i 类。下文中,颜色 1,2,3 分别对应红色、蓝色和绿色。
对于第一个测试用例,合法的字符串有:
- [1,1,2]
- [1,1,3]
- [1,2,1]
- [1,3,1]
- [2,1,1]
- [3,1,1]
对于上述任意一个字符串,我们均可先移除唯一的 2 或 3,再移除两个相邻的 1。
对于第二个测试用例,合法的字符串有:
- [1,1,3,3]
- [1,3,3,1]
- [2,2,3,3]
- [2,3,3,2]
- [3,1,1,3]
- [3,2,2,3]
- [3,3,1,1]
- [3,3,2,2]
对于第三个测试用例,显然不存在合法的字符串。
输入解题思路,AI测评打分。不知道怎么写?