Under construction

Still being built. Things may change

LaLa and Magic Stone

Time limit1sMemory limit1024 MB

Summary
Count the ways to tile all compatible cells of an N by M grid with 7-cell U-shaped pieces, modulo 998244353.
Level

Medium7 of 10

Topics
Dynamic programming, Implementation
Solved
No attempts yet

Problem

One day, \color{blue}{\text{LaLa}} realized that she ran out of magic stone components for her magic tools. (Think of them as a battery in our world.) So \color{blue}{\text{LaLa}} rushed to a nearby store and bought a slab of magic stone.

\color{blue}{\text{LaLa}} wants to cut the slab into magic stone components. The slab consists of NtimesMN \\times M cells. Unfortunately, some cells are incompatible with LaLa's magic tools.

The required magic stone component is a 7-cell U-shaped piece.

LaLa forgot to buy magic stone glue, so smaller pieces cannot be merged to form the required shape.

Also, LaLa hates wasting magic stones, so LaLa is satisfied if and only if the slab is cut so that every compatible cell belongs to a required shape.

Write a program that computes the number of ways to cut the slab so that LaLa is satisfied, modulo 998,244,353998\\,244\\,353. Two ways to cut pieces are different if and only if there exist two compatible cells such that they belong to the same piece in one and to different pieces in the other.

Input

The input is given in the following format:

NN MM

S0S\\_0

S1S\\_1

vdots\\vdots

SN−1S\\_{N-1}

where NN is the number of rows of the slab, MM is the number of columns, and SiS\\_i is a binary string of length MM whose jj-th character is '1' if and only if the cell at the ii-th row from the top and jj-th column from the left is incompatible.

The input satisfies the following constraints:

  • NN and MM are integers.
  • 3leN,Mle1,0003 \\le N, M \\le 1\\,000

Output

The output is a single integer equal to the number of ways to cut the slab so that LaLa is satisfied, modulo 998,244,353998\\,244\\,353.

Hint

The following illustrates two possible ways to cut the slab in the first sample.

The following illustrates the only way to cut the slab in the second sample.

Examples2

  1. Example 1

    Input
    4 4
    0001
    0000
    0000
    1000
    
    Expected output
    2
    
  2. Example 2

    Input
    5 4
    0001
    0101
    0000
    1010
    1000
    
    Expected output
    1