Count Subgrid

AtCoder
IDabc430_b
Time2000ms
Memory256MB
Difficulty
There is a grid with $N$ rows and $N$ columns. The cell at the $i$\-th row from the top and $j$\-th column from the left is painted black if $S_{i,j}$ is `#`, and white if it is `.`. How many distinct patterns of painted cells can be obtained by extracting a region of $M$ rows and $M$ columns from this grid? ## Constraints * $1\leq M \leq N \leq 10$ * $N$ and $M$ are integers. * $S_{i,j}$ is `.` or `#`. ## Input The input is given from Standard Input in the following format: $N$ $M$ $S_{1,1}\ldots S_{1,N}$ $\vdots$ $S_{N,1}\ldots S_{N,N}$ [samples]
Samples
Input #1
3 2
...
###
#.#
Output #1
3

The state of the given grid is as shown in the left figure below.  
There are four ways to extract a region of two rows and two columns from this grid as shown in the right figure below, and there are three distinct patterns of painted cells.
![image](https://img.atcoder.jp/abc430/f9240b594bb2c8463ffca0c0f7ec1b40.png)
Input #2
10 3
..#.......
.###......
.#.#......
#####.....
#...#.....
......####
......#..#
......#...
......#..#
......####
Output #2
36
API Response (JSON)
{
  "problem": {
    "name": "Count Subgrid",
    "description": {
      "content": "There is a grid with $N$ rows and $N$ columns. The cell at the $i$\\-th row from the top and $j$\\-th column from the left is painted black if $S_{i,j}$ is `#`, and white if it is `.`. How many distinct",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc430_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a grid with $N$ rows and $N$ columns. The cell at the $i$\\-th row from the top and $j$\\-th column from the left is painted black if $S_{i,j}$ is `#`, and white if it is `.`.\nHow many distinct...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments