However, as the puzzle author was lazy, it is not guaranteed that each word can be found in the puzzle. For a word to exist on the board, each letter of the word must exist on the board and must be sequentially adjacent to each other, either horizontally, vertically or diagonally (similar to the rules of the board game Boggle). No letter can be used more than once in the making of a single word.
Wanting to save
some time, you decide to write a program to help him search for all the words!Input Specification
On one line, space separated integers
The next
The next
Output Specification
For each word, output good puzzle!
if it can be found in the crossword, or bad puzzle!
if it cannot be found within the crossword (case insensitive).
Sample Input
4 4
p e a r
h a p s
t y i a
q s t r
pear
asfasfa
pair
pats
Sample Output
good puzzle!
bad puzzle!
good puzzle!
good puzzle!
Explanation for Sample Output
The below diagram shows how each word is made. Note that the second word cannot be found in the puzzle.
P | E | A | R |
H | A | P | S |
T | Y | I | A |
Q | S | T | R |
Comments