#P16838. [GKS 2021 #A] L Shaped Plots
[GKS 2021 #A] L Shaped Plots
Problem Description
Given a grid of rows and columns each cell in the grid is either or .
A segment is a nonempty sequence of consecutive cells such that all cells are in the same row or the same column. We define the length of a segment as number of cells in the sequence.
A segment is called "good" if all the cells in the segment contain only s.
An "L-shape" is defined as an unordered pair of segments, which has all the following properties:
- Each of the segments must be a "good" segment.
- The two segments must be perpendicular to each other.
- The segments must share one cell that is an endpoint of both segments.
- Segments must have length at least .
- The length of the longer segment is twice the length of the shorter segment.
We need to count the number of L-shapes in the grid.
Below you can find two examples of correct L-shapes,
:::align{center}
:::
and three examples of invalid L-shapes.
:::align{center}
:::
Note that in the shape on the left, segments do not share a common endpoint. The next shapes do not meet the last requirement, as in the middle shape both segments have the same length, and in the last shape the longer segment is longer than twice the length of the shorter one.
Input Format
The first line of the input contains the number of test cases, . test cases follow.
The first line of each testcase contains two integers and .
Then, lines follow, each line with integers representing the cells of the grid.
Output Format
For each test case, output one line containing Case #: , where is the test case number (starting from ) and is the number of L-shapes.
2
4 3
1 0 0
1 0 1
1 0 0
1 1 0
6 4
1 0 0 0
1 0 0 1
1 1 1 1
1 0 1 0
1 0 1 0
1 1 1 0
Case #1: 1
Case #2: 9
Hint
In Sample Case #, there is L-shape.
- The st one is formed by using cells:
:::align{center}
:::
In Sample Case #, there are L-shapes.
- The st one is formed by using cells: $(1,1), (2,1), (3,1), (4,1), (5,1), (6,1), (6,2), (6,3)$
- The nd one is formed by using cells:
- The rd one is formed by using cells:
- The th one is formed by using cells:
- The th one is formed by using cells:
- The th one is formed by using cells:
- The th one is formed by using cells:
- The th one is formed by using cells:
- The th one is formed by using cells:
The st L-shapes are shown on the picture below.
:::align{center}
:::
Limits
.
Grid consists of s and s only.
Test Set
.
.
Test Set
and for at most test cases.
For the remaining cases, and .