A11453 | Field of Wonders
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": $1$ , $3$ , $5$ and $7$ (positions are numbered from left to right starting from 1).
Polycarpus knows $m$ words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these $m$ words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": $1$ , $3$ , $5$ and $7$ (positions are numbered from left to right starting from 1).
Polycarpus knows $m$ words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these $m$ words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
输入格式
The first line contains one integer $n$ ( $1<=n<=50$ ) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length $n$ , which consists of lowercase Latin letters and symbols "\*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "\*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer $m$ ( $1<=m<=1000$ ) — the number of words of length $n$ , which Polycarpus knows. The following $m$ lines contain the words themselves — $n$ -letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given $m$ words. Before the current move Polycarp has told exactly the letters which are currently revealed.
The following line describes already revealed letters. It contains the string of length $n$ , which consists of lowercase Latin letters and symbols "\*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "\*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer $m$ ( $1<=m<=1000$ ) — the number of words of length $n$ , which Polycarpus knows. The following $m$ lines contain the words themselves — $n$ -letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given $m$ words. Before the current move Polycarp has told exactly the letters which are currently revealed.
输出格式
Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
输入输出样例
输入 #1
4 a**d 2 abcd acbd
输出 #1
2
输入 #2
5 lo*er 2 lover loser
输出 #2
0
输入 #3
3 a*a 2 aaa aba
输出 #3
1
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted