#P10893. 城市化发展委员会

城市化发展委员会

Background

The Great Emperor MLE once said:

So, to deal with this situation, we established the Urbanization Development Committee.

Problem Description

On a high school campus, we often see randomly appearing young couples. Their feelings are still too deep for OIers. Even the retired AzureHair cannot understand this behavior. However, as a standing member of the self-proclaimed Urbanization Development Committee, he has his own way to interpret it.

He believes that girls are often very strict with boys. At the start of each day, the boy’s score in the girl’s mind increases by 11. If he makes her angry xx times that day, the score decreases by xx on top of that. The score keeps accumulating, and once it becomes 0\le 0, it may lead to the serious consequence of de-urbanization.

Now William is doing a kind of urbanization behavior with Chtholly. With the help of Nahida, William gains superpowers: first, he can foresee the score changes for the next cycle, whose initial length is nn; second, he can choose to start from any day, and the days before that will be appended after the last day.

After trying starting from every day once, he finds aa starting days that can keep him from being de-urbanized. Then he concatenates the sequences of these cases in the order of their starting days, forming a new cycle whose length is aa times the original. He repeats this operation kk times. Since trying day by day is too tiring, William only wants to know, after the last operation, how many starting days can keep him from being de-urbanized, modulo 998244353998244353.


Formally, we call a sequence “safe” if all its prefix sums are always greater than 00.

For a sequence AiA_i of length nn, construct a sequence Ai+1A_{i+1} using the following algorithm. Initially, Ai+1A_{i+1} is empty.

  • Repeat nn times:
  1. If AiA_i is safe, append the entire AiA_i to the end of Ai+1A_{i+1}.

  2. Cyclically left shift AiA_i by one position, i.e. set AijAij+1modnA_{i_j} \leftarrow A_{i_{j+1 \bmod n}}.

Now given A0A_0, with every element not greater than 1.

Starting from A0A_0, generate sequences A1A_1 to Ak+1A_{k+1} according to the rules above. Please find the length ratio of Ak+1A_{k+1} to AkA_k. If this value exists, it must be an integer. Output its value modulo 998244353998244353. In particular, if AkA_k is empty, output 0.

Input Format

Plain statement:

There are two lines. The first line contains two integers nn and kk, representing the initial cycle length and the number of operations.

The second line contains nn integers not greater than 11, representing the daily score changes.

Formal statement:

There are two lines. The first line contains two integers: the length nn of A0A_0 and kk.

The second line is A0A_0.

Output Format

One line with one integer, representing the answer modulo 998244353998244353.

8 0
1 1 -2 1 1 -1 0 1
2
6 0
1 1 -4 -5 1 -4
0

Hint

[Sample Explanation 1]

For sample #1, the initial cycle is 1 1 -2 1 1 -1 0 1. The sequences obtained by starting from each day are:

1 1 -2 1 1 -1 0 1
1 -2 1 1 -1 0 1 1
-2 1 1 -1 0 1 1 1
1 1 -1 0 1 1 1 -2
1 -1 0 1 1 1 -2 1
-1 0 1 1 1 -2 1 1 
0 1 1 1 -2 1 1 -1
1 1 1 -2 1 1 -1 0

Only the sequences starting from day 4 and day 8 satisfy the condition.

Formal statement:

A1={1,1,1,0,1,1,1,2,1,1,1,2,1,1,1,0}A_1=\{1,1,-1,0,1,1,1,-2,1,1,1,-2,1,1,-1,0\}, with length 16, so the output should be 2.

[Sample Explanation 2]

It can be proven that no valid solution exists.

Hey! Isn’t it too much that all samples have k=0k=0?!

Constraints:

For 15%15\% of the testdata, 1n101\le n \le 10, 1k51\le k \le 5.

For another 25%25\% of the testdata, k=0k=0.

For 100%100\% of the testdata, 1n1061\le n\le 10^6, 0k1060 \le k \le 10^6, 109A0i1-10^9 \le {A_0}_i \le 1.

Translated by ChatGPT 5