시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB32266.667%

문제

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 contents can be inspected at here.

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).

입력

  • Lines 1..5: Line i contains five space-separated upper-case letters that are row i

출력

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

예제 입력 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

예제 출력 1

8

채점 및 기타 정보

  • 소스 코드의 크기는 4096B을 넘을 수 없다.