問題一覧 > 通常問題

No.3349 AtCoder Janken Train

レベル : / AI推定難易度 : 2275 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 13
作問者 : りすりす/TwoSquirrels / テスター : ponjuice jupiter_68 noya2
お気に入りにしたユーザー ProblemId : 12822 / 自分の提出
問題文最終更新日: 2026-10-23 17:53:54
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 作問ハッカソンコンテスト 003 Day1 (順位表) の他の問題:

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$.
    1. Let $K = 2^{N-t}$ be the current number of lines.
    2. Partition these $K$ lines into $\dfrac{K}{2}$ pairs in an arbitrary way.
    3. 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もしくは右上の雲マークをクリックしてアカウントを作成してください。