問題一覧 > 通常問題

No.3117 Reversible Tile

レベル : / AI推定難易度 : 2100 / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 47
作問者 : kenken714 / テスター : ponjuice Nzt3 Naru820
お気に入りにしたユーザー ProblemId : 12118 / 自分の提出
問題文最終更新日: 2025-04-18 00:29:35
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
CPCTF 2025 : PPC (順位表) の他の問題:

Problem Statement

There are $N$ tiles with distinguishable front and back sides, called tiles $1,2,...,N$. Initially, all tiles are face up. You will now perform the following operation $M$ times.

  • Choose positive integers $L,R$ satisfying $1 \leq L \leq R \leq N$, and flip all tiles $i\,(L\leq i \leq R)$.

Let $L_i, R_i$ be the $L, R$ chosen in the $i\,(1 \le i \le M)$-th operation, respectively.

There are $(\frac{N(N+1)}{2})^M$ operation sequences $((L_i, R_i))_{i = 1, \cdots, M}$. Among them, find the number, modulo $998244353$, of operation sequences such that the state of the tiles after all operations is $A_1,A_2,...,A_N$.

Here, $A_i = 0$ means that tile $i$ is face up, and $A_i = 1$ means that tile $i$ is face down.

Constraints

  • $1 \leq N \leq 5000$
  • $0 \leq M \leq 5000$
  • $0 \leq A_i \leq 1$
  • All inputs are integers

Input

$N\ M\\A_1\ A_2 \cdots A_N$

Output

Output the answer modulo $998244353$. Print a newline at the end.

Sample

Sample 1
Input
4 2
0 1 1 0
Output
6

The following $6$ operation sequences $((L_i, R_i))_{i = 1, 2}$ make the state of the tiles (face up, face down, face down, face up).

  • $((1, 1), (1, 3))$
  • $((1, 3), (1, 1))$
  • $((2, 2), (3, 3))$
  • $((2, 4), (4, 4))$
  • $((3, 3), (2, 2))$
  • $((4, 4), (2, 4))$
Sample 2
Input
1 56
1
Output
0

There is no operation sequence such that the tile ends up face up.

Sample 3
Input
15 121
1 0 1 1 0 0 0 1 0 0 1 1 1 0 1
Output
255247577

Output the answer modulo $998244353$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。