#P7820. [RC-05] 01 序列

    ID: 6387 远端评测题 5000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>O2优化线性递推快速数论变换 NTTBerlekamp-Massey(BM) 算法

[RC-05] 01 序列

Problem Description

There is a 0101 sequence of length nn. In any consecutive substring of length kk, there are either aa zeros or a+1a+1 zeros.

Find the number of possible sequences. The answer can be very large, so output it modulo 998244353998244353.

Input Format

To reduce the number of test points, this problem contains multiple test cases within a single test point. The time limit has been adjusted accordingly based on the number of test cases.

The first line contains the number of test cases TT.

For each test case, one line contains three integers: n,k,an, k, a.

Output Format

For each test case, output a non-negative integer, which is the number of possible sequences modulo 998244353998244353.

3
4 3 1
5 3 1
15 7 2
10
16
1586
5
999999999 14 7
233333333 14 8
333333333 14 9
114514191 14 10
981011451 14 11
278944053
533032251
736989868
589364996
572821890

Hint

This problem uses bundled judging.

For all data, 1T51\le T\le 5, 1kn1091\le k\le n\le 10^9, 1k141\le k\le 14, 0a<k0\le a<k.

The detailed Constraints are shown in the table below:

Subtask ID nn kk Special Property Score
11 18\le 18 14\le 14 None 11
22 2000\le 2000 10\le 10 88
33 109\le 10^9 14\le 14 a=0a=0 77
44 7\le 7 None 1212
55 8\le 8
66 9\le 9
77 11\le 11
88 12\le 12
99 13\le 13
1010 14\le 14

Translated by ChatGPT 5