P17474 [CodeChef] WSITES01
提高-
题目描述

Read problems statements in mandarin chinese, russian and vietnamese as well.

Mike is a network administrator in a university. One of his primary responsibilities in the job is to create an effective firewall so that the students are not able to visit the blocked sites in the network.

The network have access to exactly N sites. Some of these can be blocked. The names of the sites will be given in lowercase English letters.

The firewall will consist of several filters. A filter is a string that should be a prefix of some blocked site, and it should not be a prefix of any unblocked site. You want to minimize the sum of length of filters in the firewall so that for each of the blocked site, there should be a filter that contains the name of blocked site(filter is a prefix of blocked site).

------ Input ------

The first line of the input contains an integer N denoting the number of sites in the network.
Then N lines follow, each of them describes the site. Each line starts from the char С. If the site is unblocked, С is equal to '+', otherwise С is equal to '-'., followed by a string denoting the name of the site.

------ Output ------

If it is not possible to choose set of filters and satisfy all constraints, output a single line containing an integer -1.
Otherwise, in the first line print the number of filters K in the firewall. Then print K lines, in each line print the chosen filter. Please dislpay them in lexicographical order. You can prove that answer will be unique.

------ Constraints ------

$1 ≤ N ≤ 2 * 10^{5}$
$The sum of lengths of names of sites does not exceed 2*10^{5}$
$No two sites have same name.$

------ Subtasks ------

$Subtask #1 (30 points) 1 ≤ N, the sum of lengths of names of sites ≤ 3 * 10^{3}$
$Subtask #2 (70 points) Original constraints$

----- Sample Input 1 ------
4

  • codeforces

  • codechef

  • youtube

  • google
    ----- Sample Output 1 ------
    2

codef

y
----- explanation 1 ------
You can see that the filter "codef" is a prefix of the blocked site "codeforces", but not a prefix of approved sites "codechef" and "google". Similarly, filter "y" is also a prefix of blocked site "youtube", but not a prefix of the approved sites. You can also see that there exists at least one filter for both the blocked sites "codeforces" and "youtube".

输入格式

见题面

输出格式

见题面

样例输入
4 - codeforces + codechef - youtube + google
样例输出
2 codef y