시간 제한메모리 제한제출정답맞힌 사람정답 비율
30 초 (추가 시간 없음) 512 MB0000.000%

문제

Gagan just got an email from her friend Jorge. The email contains important information, but unfortunately it was corrupted when it was sent: all of the spaces are missing, and after the removal of the spaces, some of the letters have been changed to other letters! All Gagan has now is a string S of lower-case characters.

You know that the email was originally made out of words from the dictionary described below. You also know the letters were changed after the spaces were removed, and that the difference between the indices of any two letter changes is not less than 5. So for example, the string "code jam" could have become "codejam", "dodejbm", "zodejan" or "cidejab", but not "kodezam" (because the distance between the indices of the "k" change and the "z" change is only 4).

What is the minimum number of letters that could have been changed?

The dictionary contains W words of at least 1 and at most 10 lower-case characters and is given at the start of the input file. It is not a dictionary from any natural language, though it does contain some English words. The dictionary is the same for all test cases in a single input file. The dictionary is given in lexicographically increasing order and does not contain duplicate words.

입력

The first line of the input gives the number of words in the dictionary, W. Each of the next W lines contains a string of lower-case characters a-z representing a word in the dictionary. The next line of the input gives the number of test cases, T. T test cases follow. Each test case consists of a single line containing a string S, consisting of lower-case characters a-z.

출력

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the minimum number of letters that could have been changed in order to make S.

제한

  • W = 521196.
  • Each word in the dictionary contains at least 1 and at most 10 lower-case characters.
  • The dictionary is sorted in lexicographically increasing order.
  • The dictionary does not contain duplicate words.
  • The total number of characters in the dictionary is 3323296.
  • S is valid: it is possible to make it using the method described above.
  • 1 ≤ T ≤ 20.
  • 1 ≤ length of S ≤ 50.

예제 입력 1

9
aabea
bobs
code
in
jam
oo
operation
production
system
4
codejam
cxdejax
cooperationaabea
jobsinproduction

예제 출력 1

Case #1: 0
Case #2: 2
Case #3: 1
Case #4: 1

힌트

"code" and "jam" both appear in the dictionary. Although "cooperation" is an English word, it doesn't appear in the dictionary; "aabea" does.

Note that to make the sample case visible in the problem statement, the size of the dictionary in the sample case does not satisfy the limits.

출처

Contest > Google > Code Jam > Google Code Jam 2013 > Round 1B C1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.