Hacker
Time limit1sMemory limit128 MB
Build the minimal list of URLs that covers every known parameter with every malicious value, packing pairs into queries of at most P parameters by the given grouping rule.
- Level
Medium5 of 10
- Topics
- Implementation, String, Greedy, Sorting
- Solved
- No attempts yet
Problem
Mirko recently got a job as a hacker. The first task his boss gave him is to write a tool that automatically finds frequent errors on his office's website.
A web page name (URL) has two parts: the address and the query.
The address is a string that starts with http://, and the rest of it consists of lowercase and uppercase English letters, dots ., and slashes /. The address and the query are separated by a question mark ?, which appears exactly once in the URL. The query consists of one or more parameters. Each parameter is an ordered pair of a name and a value, separated by an equals sign =. A parameter name is always a string of lowercase English letters. A parameter value is a string of lowercase and uppercase English letters, digits, and spaces (ASCII 32). A query can contain several parameters separated by &. No two parameters in one query have the same name.
Hackers often try to gain unauthorized access to a web page by changing parameter values. From the given URLs and a list of frequent malicious values, Mirko has to build a new list of URLs in which every known parameter is called with every malicious value at least once. A known parameter is a parameter name that appears in at least one input URL. To make errors easier to find, Mirko may use at most parameters in one query. Fetching a URL takes several seconds, so the total number of URLs must be as small as possible.
Input
The first line contains three positive integers , , and :
- (), the number of given URLs,
- (), the maximum number of parameters Mirko may use in one URL,
- (), the number of frequent malicious values.
Each of the next lines contains one URL. All URLs have the same address. All URLs are syntactically valid as described above. Each URL is at most 250 characters long and has at least one parameter.
Each of the next lines contains one malicious value. Each malicious value is at most 25 characters long and is a valid parameter value. A malicious value may start or end with a space.
Output
Print a list of URLs in which every known parameter is called with every malicious value at least once, one URL per line. A URL may contain only known parameters and malicious values.
Several lists can satisfy these conditions, so print the list built by the following rule. The list it builds has the smallest possible number of URLs.
- Let be the number of known parameter names, and sort the names in lexicographic order.
- Go through the malicious values in input order, and pair each value with every sorted name in turn. This gives a sequence of (name, value) pairs.
- Split the sequence, from the start, into groups of pairs. The last group may be smaller.
- Print one URL per group. The URL is the address of the input URLs, then
?, then the query formed by writing the pairs of the group in order asname=valueand joining them with&.