QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 256 MB 총점: 100

#22380. Coggle

통계

Like everyone else on their vacation, the cows play the cow version of the word game called Boggle: Coggle. It's a similar game where 25 letter dice are rolled into a matrix like this one:

           Z C C D X
           K Q M N B
           U O W Z Y
           F C O I J
           P A Q Z T

Words are made (and thus points scored) by starting at some letter and proceeding to one of its (as many as) eight neighbors, etc. until the successive letters spell out a word from a dictionary

In the matrix above, the lower '$C$' can be used to form the words "CAP", "COW", and "COOK" (but not "COD" or "PACK"). The complete list of dictionary words for the above square is: "CAP", "COOK", "COW", "OWN", "WIT", "WOO", "ZOO", and "ZOOM".

Your program should read the dictionary from file dict.txt (which is alphabetized and has fewer than 25,000 words; each word is no longer than 20 characters). The actual dictionary is provided as dict.txt in the attachments and is available in the working directory during judging.

Help Bessie see how good she can do. Read in five rows of five letters that represent the dice and see how many words from the dictionary can be formed. Don't use any given die's letter twice in the same word.

Count the number of words that can be formed (a number that might well be smaller than the number of ways a word a can be formed since words might be formed in more than one way).

Input

  • Lines $1,\ldots,5$: Line $i$ contains five space-separated upper-case letters that are row $i$

Output

  • Line $1$: A single integer that is the number of words in the dictionary that can be formed using the described rules

Examples

Input 1

Z C C D X
K Q M N B
U O W Z Y
F C O I J
P A Q Z T

Output 1

8

Problem credits: Traditional, 2009

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.