No.3349 AtCoder Janken Train
タグ : / 解いたユーザー数 13
作問者 :
noya2
Problem Statement
$2^N$ distinguishable people will play the AtCoder Janken Train. Of the $2^N$ people, $M$ are "cool-colored" and the remaining $2^N - M$ are "warm-colored".
Find the total number of possible arrangements of the final line after the AtCoder Janken Train has finished, modulo $998244353$.
Here, the AtCoder Janken Train is defined as the following procedure.
- First, the $2^N$ people form $2^N$ lines, each consisting of $1$ person.
- If $N \ge 1$, then for $t = 0, 1, \dots, N - 1$, in this order, perform the following operation for the integer $t$.
- Let $K = 2^{N-t}$ be the current number of lines.
- Partition these $K$ lines into $\dfrac{K}{2}$ pairs in an arbitrary way.
- For each of the resulting $\dfrac{K}{2}$ pairs $(L_A, L_B)$, perform the following operation to make $\dfrac{K}{2}$ new lines.
- Let $h_A$ be the person at the front of $L_A$, and $h_B$ be the person at the front of $L_B$.
- $h_A$ and $h_B$ play janken (rock-paper-scissors) until one of them wins.
- If $h_A$ is "cool-colored" and $h_B$ is "warm-colored", attach $L_A$ behind $L_B$ to make a new line.
- If $h_A$ is "warm-colored" and $h_B$ is "cool-colored", attach $L_B$ behind $L_A$ to make a new line.
- Otherwise, if $h_A$ won the janken, attach $L_B$ behind $L_A$, and if $h_B$ won, attach $L_A$ behind $L_B$, to make a new line.
After all the operations are finished, there is exactly $1$ line.
Constraints
- $0 \le N \le 18$
- $0 \le M \le 2^N$
- $N, M$ are integers.
Input
The input is given from standard input in the following format.
$N$ $M$
Output
Output the answer.
Sample
Sample 1
Input
2 2
Output
8
Let $A, B$ be the $2$ cool-colored people and $C, D$ be the $2$ warm-colored people.
Then, one concrete example of the procedure is as follows.
- When $t=0$:
- $K = 2^{2-0} = 4$
- Pairs made: $((A), (C))$ and $((B), (D))$
- Janken results: $A$ beat $C$, and $D$ beat $B$
- Resulting lines: $(C, A)$ and $(D, B)$
- When $t=1$:
- $K = 2^{2-1} = 2$
- Pair made: $((C, A), (D, B))$
- Janken result: $C$ beat $D$
- Resulting line: $(C, A, D, B)$
The possible final lines are the $8$ lines $(C, A, D, B)$, $(C, B, D, A)$, $(C, D, A, B)$, $(C, D, B, A)$, $(D, A, C, B)$, $(D, B, C, A)$, $(D, C, A, B)$, $(D, C, B, A)$, so output 8.
Sample 2
Input
3 0
Output
40320
Since all $2^3 = 8$ people are warm-colored, the people at the front of any two lines are always both warm-colored, and there are always $2$ choices for the order of attaching. Thus, the total number is $8! = 40320$.
Sample 3
Input
18 192109
Output
659921266
Note that you should output the remainder modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。