COCI '25 Contest 5 #3 Pet
View as PDF
Frog Maša is in a lake represented by a matrix with rows and
columns. The cells of the matrix are marked with
0 (water) or 1 (water lily). From one water lily, Maša can jump to any other water lily in the same row or column. If in the previous jump Maša changed the column she was in, then in the next jump she must change the row she is in. If in the previous jump Maša changed the row she was in, then in the next jump she must change the column she is in. After Maša jumps from the water lily she is currently on, it sinks and can no longer be jumped on.
Maša likes to have fun and wants to visit a total of water lilies along her path (including the starting water lily).
Help her and calculate in how many ways she can do this if she can choose any water lily as her starting point. Two paths are considered different if the positions of their first, second, third, fourth, or fifth water lilies differ.
Input Specification
The first line contains the natural numbers and
, as described in the problem statement.
In each of the following lines there are
characters, which are either
0 or 1 and represent the cells of the lake.
Output Specification
Print a single number, the answer to the question from the problem statement.
Constraints
| Subtask | Points | Constraints |
|---|---|---|
| No additional constraints. |
Sample Input 1
2 3
111
110
Sample Output 1
4
Explanation for Sample Output 1
The possible jump paths on water lilies are:
Sample Input 2
4 4
1111
1111
1111
1111
Sample Output 2
2304
Sample Input 3
2 5
11110
01111
Sample Output 3
48
Comments