#P15987. [PA 2026] 多重桥牌 / Multi-brydż
[PA 2026] 多重桥牌 / Multi-brydż
Problem Description
In the game of multiple bridge, there are two teams (we call them the "Keban-zhe" and the "Algorithmists"), each consisting of players.
The players sit around a round table, with positions numbered from to . The Keban-zhe sit in odd positions, and the Algorithmists sit in even positions. The game uses cards with face values . Each player holds two of these cards at the start of the game. Every player knows the cards held by all other players.
The game consists of two rounds. In the first round, the player at a random position plays first and plays one of their two cards. Then, the players at positions $(i \bmod 2n) + 1,\ (i+1 \bmod 2n) + 1,\ \ldots,\ (i+2n-2 \bmod 2n) + 1$ play in order (each plays one of their two cards). The team of the player who played the highest-valued card gets point. In the second round, all players play their remaining card. Again, the team of the player who played the highest-valued card gets point.
The input gives a sequence of integers describing the relationship between the game outcome and the starting player. Specifically, for , if the player at position plays first and all players use optimal strategies, then the Algorithmists team gets exactly points.
Compute the number of different dealing arrangements consistent with the given outcome sequence, and output this number modulo . If for some position and some card value , the player at position holds the card with value in one arrangement but does not hold it in another, then these two dealing arrangements are considered different.
You need to solve this problem for independent test cases.
Input Format
The first line contains an integer (), the number of test cases.
For each test case, the first line contains an integer (), the number of players on each team.
The second line contains a sequence of integers (). The value indicates the number of points the Algorithmists team gets when the player at position plays first.
The sum of over all test cases does not exceed .
Output Format
Output lines. The -th line should contain one integer: the number of dealing arrangements consistent with the outcome sequence of the -th test case, modulo .
4
2
1 0 1 0
1
0 2
3
1 0 0 1 1 0
7
1 1 1 1 1 1 1 1 1 1 1 1 1 1
24
0
0
256223893
Hint
Sample Explanation
In the first test case, one dealing arrangement consistent with the given input outcome sequence is: the first player holds cards and , the second player holds and , the third player holds and , and the fourth player holds and .
In the second and third test cases, there is no dealing arrangement consistent with the given input outcome sequence.
Translated by ChatGPT 5