Submit | All submissions | Best solutions | Back to list |
AU10_GAME - Drunken Sailor |
Vishnu has just now started traveling to Ireland from New London through ship. In his ship there is a drunken sailor who is disturbing others and also stole his pizza. He got so pissed off and was thinking of how to make him stop disturbing people. Some of his thoughts.
So after so much of thinking he gave one problem to drunken sailor to solve. The problem is, the drunken sailor is given an array of string. Then he is given with a set of queries. Each query has a single string. Sailor has to tell Vishnu the cost of the costliest query. Cost of a query (a string) is defined as sum of the cost of it's prefixes. Cost of a prefix is the number of strings it is prefixed with, in the given array of string.
Calculating the cost of a string is illustrated in the following example.
For example array of string is ["ab", "ab", "abc"], say a query has a string, "abc", it's cost will be equal to cost("a") = 3 ("a" is prefix for "ab", "ab", "abc" in the array).
cost("ab") = 3 ("ab" is prefix for "ab", "ab", "abc").
cost("abc") = 1 ("abc" is prefix for "abc").
So you're going to help drunken sailor by returning cost of the costliest query.
Input
T - Number of test cases (1 <= T <= 100).
N - Size of the array of string (1 <= N <= 100000).
N strings, each in a line. Each string's length will between 1 and 100. It has only lower case characters. ('a' - 'z').
M - Number of queries. (1 <= M <= 100).
M strings, each in a line. Each string's length will between 1 and 100. It has only lower case characters. ('a' - 'z').
Output
Cost of the costliest query for each test case, each in a line.
Example
Input: 1
3
ab
ab
abc
2
abc
a Output: 7
Explanation - Cost("abc") is 7, cost("a") is 3. So cost of the costliest query is 7.
Added by: | Noob |
Date: | 2015-11-28 |
Time limit: | 2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 MAWK BC NCSHARP COFFEE DART FORTH GOSU JS-MONKEY JULIA KTLN OCT PROLOG PYPY3 R RACKET SQLITE SWIFT UNLAMBDA |
Public source code since: | 2015-11-29 19:30:00 |