codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

883E.md (3324B)


      1 Source: https://codeforces.com/problemset/problem/883/E
      2 
      3 E. Field of Wonders
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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).
     24 
     25 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.
     26 
     27 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.
     28 
     29 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.
     30 
     31 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.
     32 
     33 Input
     34 
     35 The first line contains one integer *n* (1 ≤ *n* ≤ 50) — the length of the hidden word.
     36 
     37 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.
     38 
     39 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.
     40 
     41 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.
     42 
     43 Output
     44 
     45 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.
     46 
     47 Examples
     48 
     49 Input
     50 
     51 ```
     52 4  
     53 a**d  
     54 2  
     55 abcd  
     56 acbd
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 2
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 5  
     69 lo*er  
     70 2  
     71 lover  
     72 loser
     73 ```
     74 
     75 Output
     76 
     77 ```
     78 0
     79 ```
     80 
     81 Input
     82 
     83 ```
     84 3  
     85 a*a  
     86 2  
     87 aaa  
     88 aba
     89 ```
     90 
     91 Output
     92 
     93 ```
     94 1
     95 ```
     96 
     97 Note
     98 
     99 In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
    100 
    101 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.
    102 
    103 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.