Chino's Latte Art (Easy)
InterviewTime limit1sMemory limit1024 MB
Given a grid of cream cells, decide whether they form exactly one N x N square with an M x M corner removed, with no holes or extra lumps.
- Level
Easy3 of 10
- Topics
- Implementation, Brute force, Matrix
- Solved
- No attempts yet
Problem
Chino is practicing making heart-shaped latte art. Cocoa happened to see the many traces of Chino's practice and became curious how many heart-shaped latte art pieces there are. Write a program that determines whether the cream on a latte is heart-shaped, for Cocoa.
Heart shape
Chino's latte art is given as a two-dimensional grid divided into unit squares. # is a square fully filled with cream, and . is a square with no cream.
Two positive integers and () define a heart as an square with an square removed from one of its four corners.
The following is a heart for , .
###..
###..
#####
#####
#####
A latte is counted as a heart only when exactly one shape defined above is placed on it. If the cream has a hole, or if it consists of several separate lumps (including the case where each lump is heart-shaped), it is not considered a heart.
Input
The first line contains the number of test cases (). The next lines contain test cases in the following format.
The first line of each test case contains the number of rows and columns of the grid, separated by a space. ()
The next lines contain strings of length representing rows to of the grid. Each string consists only of # and ..
Output
For each test case, print 1 if the latte art is a heart, and 0 otherwise, one per line.