A11558 | Shockers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains a single integer $n$ ( $1<=n<=10^{5}$ ) — 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 $10^{5}$ .
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.
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 $10^{5}$ .
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.
输出格式
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted