CF1545B.AquaMoon and Chess
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Cirno gave AquaMoon a chessboard of size 1×n. Its cells are numbered with integers from 1 to n from left to right. In the beginning, some of the cells are occupied with at most one pawn, and other cells are unoccupied.
In each operation, AquaMoon can choose a cell i with a pawn, and do either of the following (if possible):
- Move pawn from it to the (i+2)-th cell, if i+2≤n and the (i+1)-th cell is occupied and the (i+2)-th cell is unoccupied.
- Move pawn from it to the (i−2)-th cell, if i−2≥1 and the (i−1)-th cell is occupied and the (i−2)-th cell is unoccupied.
You are given an initial state of the chessboard. AquaMoon wants to count the number of states reachable from the initial state with some sequence of operations. But she is not good at programming. Can you help her? As the answer can be large find it modulo 998244353.
Cirno 给了 AquaMoon 一个大小为 1×n 的棋盘。其单元格从左到右依次编号为 1 到 n。初始时,某些单元格中至多放置一枚兵(pawn),其余单元格为空。
在每次操作中,AquaMoon 可以选择一个有兵的单元格 i,并执行以下两种操作之一(若可行):
- 若 i+2≤n,且第 (i+1) 个单元格被占据、第 (i+2) 个单元格为空,则可将该兵移动至第 (i+2) 个单元格;
- 若 i−2≥1,且第 (i−1) 个单元格被占据、第 (i−2) 个单元格为空,则可将该兵移动至第 (i−2) 个单元格。
你将获得棋盘的初始状态。AquaMoon 想要计算:从该初始状态出发,经若干次操作后所能到达的不同状态的总数。但她不擅长编程。你能帮她吗?由于答案可能很大,请对 998244353 取模输出结果。
输入格式
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤10000) — the number of test cases.
The first line contains a single integer n (1≤n≤105) — the size of the chessboard.
The second line contains a string of n characters, consists of characters "0" and "1". If the i-th character is "1", the i-th cell is initially occupied; otherwise, the i-th cell is initially unoccupied.
It is guaranteed that the sum of n over all test cases does not exceed 105.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤10000),表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤105),表示棋盘的大小。
第二行包含一个长度为 n 的字符串,仅由字符 "0" 和 "1" 组成。若第 i 个字符为 "1",则第 i 个格子初始时被占据;否则,第 i 个格子初始时为空。
保证所有测试用例的 n 之和不超过 105。
输出格式
For each test case, print the number of states that reachable from the initial state with some sequence of operations modulo 998244353.
对于每个测试用例,输出从初始状态出发、通过若干次操作可达的状态数量,结果对 998244353 取模。
输入输出样例
输入#1
6 4 0110 6 011011 5 01010 20 10001111110110111000 20 00110110100110111101 20 11101111011000100010
输出#1
3 6 1 1287 1287 715
说明/提示
In the first test case the strings "1100", "0110" and "0011" are reachable from the initial state with some sequence of operations.
在第一个测试用例中,字符串 “1100”、“0110” 和 “0011” 均可通过若干次操作从初始状态到达。
输入解题思路,AI测评打分。不知道怎么写?