Bingo
Time limit1sMemory limit1024 MB
Given a partly colored n by n bingo board and k more random calls, find the expected number of fully colored lines, scaled by (n^2)! modulo 1e9+7.
- Level
Medium5 of 10
- Topics
- Math, Combinatorics, Probability, Implementation
- Solved
- No attempts yet
Problem
Students in a probability and statistics course are playing bingo. The game follows these rules.
- Each participant writes the integers from 1 to into the cells of an square board, one per cell, with no repeats.
- In each round, the host calls one of the integers from 1 to . A number that has already been called cannot be chosen again.
- Each participant finds the cell containing the called number on their own board and fills it with color.
- When the host decides to stop calling numbers, the game ends and scores are computed. A participant's score is the number of lines made up only of colored cells. There are lines to consider: rows, columns, and 2 diagonals.

The score of the board above is 5.
The host is completely fair. Each turn, the host picks uniformly at random from the numbers that may be called.
You are given the board of participant , reflecting the game so far. The host will call exactly more numbers. Find the expected final score of .
Input
The first line contains two integers and . ,
From the second line onward, the state of the board is given as strings of length consisting of and . means the cell is not colored, and means the cell is colored.
The given board has at least uncolored cells.
Output
Let be the expected score of . Print a single integer on the first line: the value of modulo the prime .
Within the given input range, is always an integer.