CCCCUBE - Cube
Imagine a cube formed from solid interlocking pieces of various shapes. If the pieces are sufficiently intertwined, the only way to separate them would be to cut some of them. We can ask the question, "is the cube stable?" That is, is it physically impossible to separate the cube into 2 or more fragments without deforming and cutting any individual piece?
Your program must answer this question for a variety of such cubes. The pieces that make up a cube will be specified as follows: divide the cube into a grid of n*n*n miniature cubes, each labelled by a capital letter. Two adjacent (face-sharing) are joined together if and only if they are labelled by the same letter. For instance, the first example cube given consists of 3 solid pieces.
Input
Your program will be given the specification of up to 10 different cubes. The first two lines of each specification will consist of the size of that cube, n (1 ≤ n ≤ 10), and a blank line. There will be no spaces in the input. The input will be terminated by a number 0 on a line by itself.
Output
For each cube given, in the order specified, print "Yes" if that cube is stable, and "No" if it is not.
Example
Input: 2 AB AB BB BA 3 AAA BBB AAA AAA ABA AAA ABA ABA ABA 0 Output: No Yes
Added by: | Brian Bi |
Date: | 2009-04-08 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 NODEJS OBJC PERL6 SQLITE VB.NET |
Resource: | 2003 Canadian Computing Competition Stage 2 - Day 1, Question 3 |