AtCoder Regular Contest 136
F
Flip Cells
AtCoder
⌀ 3554
原题
← E→
翻译中…

Problem Statement

翻译中…

We have a checkerboard with $H$ rows and $W$ columns, where each square has a 0 or 1 written on it. The current state of checkerboard is represented by $H$ strings $S_1,S_2,\cdots,S_H$: the $j$-th character of $S_i$ represents the digit in the square at the $i$-th row from the top and $j$-th column from the left.

翻译中…

Snuke will repeat the following operation.

翻译中…
  • Choose one square uniformly at random. Then, flip the value written in that square. (In other words, change 0 to 1 and vice versa.)
翻译中…

By the way, he loves an integer sequence $A=(A_1,A_2,\cdots,A_H)$, so he will terminate the process at the moment when the following condition is satisfied.

翻译中…
  • For every $i$ ($1 \leq i \leq H$), the $i$-th row from the top contains exactly $A_i$ 1s.
翻译中…

Particularly, he may do zero operations.

翻译中…

Find the expected value of the number of operations Snuke does, modulo $998244353$.

翻译中…

Definition of the expected value modulo $998244353$ It can be proved that the sought expected value is always a rational number. Additionally, under the Constraints of this problem, when that value is represented as an irreducible fraction $\frac{P}{Q}$, it can also be proved that $Q \not \equiv 0 \pmod{998244353}$. Thus, there uniquely exists an integer $R$ such that $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$. Find this $R$.

翻译中…

Constraints

翻译中…
  • $1 \leq H,W \leq 50$
  • $S_i$ is a string of length $W$ consisting of 0, 1.
  • $0 \leq A_i \leq W$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

H W
S_1
S_2
\vdots
S_H
A_1 A_2 \cdots A_H

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
1 2
01
0
Output #1
3
The process goes as follows. - With probability $1/2$, a square with `1` is flipped. The $1$-st row now contains zero `1`s, terminating the process. - With probability $1/2$, a square with `0` is flipped. The $1$-st row now contains two `1`s, continuing the process. - One of the squares is flipped. Regardless of which square is flipped, the $1$-st row now contains one `1`, continuing the process. - With probability $1/2$, a square with `1` is flipped. The $1$-st row now contains zero `1`s, terminating the process. - With probability $1/2$, a square with `0` is flipped. The $1$-st row now contains two `1`s, continuing the process. - $\vdots$ The expected value of the number of operations is $3$.
Input #2
3 3
000
100
110
0 1 2
Output #2
0
Input #3
2 2
00
01
1 0
Output #3
332748127
Input #4
5 4
1101
0000
0010
0100
1111
1 3 3 2 1
Output #4
647836743
题目信息
题号
arc136_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。