Bear and Chocolate
Practice
3.9 (58 votes)
Approved
Easy
Implementation
Open
Problem
61% Success 4393 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

View Russian Translation

Limak is a little polar bear. Today he found something delicious in the snow. It's a square bar of chocolate with N x N pieces. Some pieces are special because there are cherries on them. You might be surprised by cherries on a chocolate but you've never been on the Arctic Circle, have you?

Limak is going to use his claws and break a chocolate into two parts. He can make a cut between two rows or between two columns. It means that he can't break any piece!

Limak will eat one part right now, saving the second part for tomorrow. Cherries are very important to him so he wants to have equal number of cherries today and tomorrow. Though parts don't have to have equal numbers of pieces of chocolate.

Given description of a chocolate, could you check if Limak can make a cut dividing a chocolate into two parts with equal number of cherries?

Note: It's guaranteed that a chocolate contains at least one cherry.

Input format:

The first line contains one integer number T, denoting number of test cases. Then T test cases follow, each describing one bar of chocolate.

For each test case the first line contains one integer number N, denoting size of a chocolate. Each of the next N lines contains a string of size N. Each character in a string is either # (denoting cherry) or . (empty piece). In each test case at least one character is #.

Output format:

For each test case output an answer in the single line. If Limak can break a chocolate according to rules above print YES. Otherwise, print NO.

Constraints:

1 <= T <= 10
2 <= N <= 1000

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
30 votes
Tags:
ApprovedCombinatoricsEasyMathOpenString Manipulation
Points:20
32 votes
Tags:
ApprovedBasic ProgrammingEasyOpen
Points:20
53 votes
Tags:
Ad-HocEasyImplementation