1070H.md (2404B)
1 Source: https://codeforces.com/problemset/problem/1070/H 2 3 H. BerOS File Suggestion 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 Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature. 22 23 There are $n$ files on hard drive and their names are $f_1, f_2, \dots, f_n$. Any file name contains between $1$ and $8$ characters, inclusive. All file names are unique. 24 25 The file suggestion feature handles queries, each represented by a string $s$. For each query $s$ it should count number of files containing $s$ as a substring (i.e. some continuous segment of characters in a file name equals $s$) and suggest any such file name. 26 27 For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is $2$ (two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18". 28 29 Input 30 31 The first line of the input contains integer $n$ ($1 \le n \le 10000$) — the total number of files. 32 33 The following $n$ lines contain file names, one per line. The $i$-th line contains $f_i$ — the name of the $i$-th file. Each file name contains between $1$ and $8$ characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique. 34 35 The following line contains integer $q$ ($1 \le q \le 50000$) — the total number of queries. 36 37 The following $q$ lines contain queries $s_1, s_2, \dots, s_q$, one per line. Each $s_j$ has length between $1$ and $8$ characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.'). 38 39 Output 40 41 Print $q$ lines, one per query. The $j$-th line should contain the response on the $j$-th query — two values $c_j$ and $t_j$, where 42 43 * $c_j$ is the number of matched files for the $j$-th query, 44 * $t_j$ is the name of any file matched by the $j$-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any. 45 46 Example 47 48 Input 49 50 ``` 51 4 52 test 53 contests 54 test. 55 .test 56 6 57 ts 58 . 59 st. 60 .test 61 contes. 62 st 63 ``` 64 65 Output 66 67 ``` 68 1 contests 69 2 .test 70 1 test. 71 1 .test 72 0 - 73 4 test. 74 ```