#P5757. [NOI2000] 古城之谜

[NOI2000] 古城之谜

Description

The famous archaeologist Professor Shi discovered an ancient city ruin on the Yunmeng Plateau. To his delight, in this city that he called Ice-Peak City, there were 1212 huge stone tablets, engraved with information written in some kind of script, which he named the Ice-Peak script. However, when Professor Shi tried to find Ice-Peak City again, he failed again and again.

Fortunately, he had photographed all the text on the tablets. In order to uncover the secrets of Ice-Peak City, Professor Shi and his assistant Dr. Niu began to study the Ice-Peak script. They found that the Ice-Peak script has only one sentence type: declarative sentences, and only three categories of words: nouns (n), verbs (v), and auxiliary words (a). Its grammar is very simple:

After studying a large amount of material, they summarized an Ice-Peak dictionary. Since the Ice-Peak script happens to have 2626 letters, for convenience they use the letters aa to zz to represent them.

In the Ice-Peak script, there are no separators between sentences, nor between words. So splitting words and sentences is very troublesome for Professor Shi and Dr. Niu. They decided to use a computer to help solve this problem. Suppose you accept this job. Your first task is to write a program that splits an Ice-Peak article into the minimum number of sentences, and under this premise, splits the article into the minimum number of words.

Input Format

  • Line 11 contains the number of words in the dictionary nn (n1000n \le 1000).
  • Lines 22 to (n+1)(n+1) each describe one word, in the form "α.mot""α.mot". Here αα is the part of speech, which can be one of n (noun), v (verb), a (auxiliary word), and motmot is the word. The word length does not exceed 2020. Words with the same spelling but different parts of speech are considered different words. For example, n.kick and v.kick in the sample input are two different words.
  • Line (n+2)(n+2) of the input file is the article to be split, ending with ".".
  • The article in the input file is guaranteed to be in the Ice-Peak script. The article consists of finitely many sentences, and each sentence contains only finitely many words. The article length does not exceed 5 KB.

Output Format

  • Output two lines, each containing one integer.
  • Line 11 is the number of sentences after splitting.
  • Line 22 is the number of words after splitting.
11
n.table
n.baleine
a.silly
n.snoopy
n.sillysnoopy
v.is
v.isnot
n.kick
v.kick
a.big
v.cry
sillysnoopyisnotbigtablebaleinekicksnoopysillycry.

2
9

Hint

Sample Explanation

(For easier reading, the split words are separated by spaces, the part of speech is marked at the upper right of each word, one sentence per line, and a period indicates the end of a sentence.)

The output corresponds to the following splitting:

$sillysnoopy^n \quad isnot^v \quad big^a \quad table^n. \\ baleine^n \quad kick^v \quad snoopy^n \quad silly^a \quad cry^v.$

If the following splitting is used:

$silly^a \quad snoopy^n \quad isnot^v \quad big^a \quad table^n. \\ baleine^n \quad kick^v \quad snoopy^n \quad silly^a \quad cry^v.$

then the number of sentences is still 22, but the number of words increases by 11 to 1010. Clearly, the former splitting should be chosen rather than the latter.

Translated by ChatGPT 5