CF906A.Shockers

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.

Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks.

瓦伦丁参加了一个名为“震动者”(Shockers)的节目。规则非常简单:评委选定一个瓦伦丁不知道的字母,他需要发表一段简短演讲;但每当他说出一个包含该选定字母的单词时,就会遭受一次电击。他可以猜测被选定的是哪个字母,但每次猜错也会遭受一次电击。当瓦伦丁正确猜中选定字母时,节目结束。

瓦伦丁的记忆力有限,因此他可能在该选定字母已被唯一确定之后很久才猜中,从而承受了额外的电击。“额外电击”指的是:在选定字母已被唯一确定之后,瓦伦丁所遭受的那些电击。你需要计算出额外电击的次数。

输入格式

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.

The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:

  1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and w is the word that Valentin said.
  2. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and w is the word that Valentin said.
  3. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and s is the guess — a lowercase English letter.

All words consist only of lowercase English letters. The total length of all words does not exceed 105.

It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)—— 表示瓦伦丁执行的操作次数。

接下来的 nn 行描述了他的操作,每行描述一次操作。每次操作属于以下三种类型之一:

  1. 瓦伦丁说出某个单词,但未受到电击。该操作用字符串 . w(不含引号)表示,其中 . 是英文句点(ASCII 码为 46),ww 是瓦伦丁说出的单词。
  2. 瓦伦丁说出某个单词,并受到了电击。该操作用字符串 ! w(不含引号)表示,其中 ! 是英文感叹号(ASCII 码为 33),ww 是瓦伦丁说出的单词。
  3. 瓦伦丁对所选字母进行了猜测。该操作用字符串 ? s(不含引号)表示,其中 ? 是英文问号(ASCII 码为 63),ss 是他的猜测——一个小写英文字母。

所有单词仅由小写英文字母组成,所有单词的总长度不超过 10510^5。

保证最后一次操作是对所选字母的猜测。此外,保证瓦伦丁在最后一次操作之前从未正确猜中过所选字母。同时,保证:若瓦伦丁在说出某个单词后受到电击,则该单词中一定包含所选字母;若瓦伦丁在说出某个单词后未受到电击,则该单词中一定不包含所选字母。

输出格式

Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.

输出一个整数——如果瓦连京在所选字母刚变得唯一确定时就立刻说出该字母,那么他本可以避免的电击次数。

输入输出样例

  • 输入#1

    5
    ! abc
    . ad
    . b
    ! cd
    ? c

    输出#1

    1
  • 输入#2

    8
    ! hello
    ! codeforces
    ? c
    . o
    ? d
    ? h
    . l
    ? e

    输出#2

    2
  • 输入#3

    7
    ! ababahalamaha
    ? a
    ? b
    ? a
    ? b
    ? a
    ? h

    输出#3

    0

说明/提示

In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces the word cd and gets an excessive electric shock.

In the second test case after the first two electric shocks we understand that the selected letter is e or o. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is e, but Valentin makes 3 more actions before he makes a correct hypothesis.

In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks.

在第一个测试用例中,第一次操作后即可确定所选字母为以下之一:a、 b、 c。第二次操作后,我们可推知所选字母不是 a。瓦伦丁说出单词 “b”,未受到电击。此后便可确定所选字母为 c,但瓦伦丁却念出了单词 cd,从而受到了一次额外的电击。

在第二个测试用例中,前两次电击之后,我们便知道所选字母是 e 或 o。瓦伦丁尝试了一些仅由这些字母组成的单词;在第二个单词之后,即可明确所选字母为 e,但瓦伦丁又进行了 3 次额外操作,才最终做出正确猜测。

在第三个例子中,所选字母仅当瓦伦丁猜中时才能被唯一确定,因此他并未受到任何额外的电击。

输入解题思路,AI测评打分。不知道怎么写?

首页