QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#15055. Virus Classification

Statistics

Background

A rare case of laziness and procrastination has broken out in JSOI. To save his friends from this plight, JYY has collected the DNA sequences of all viruses in the JSOI kingdom and hopes to classify these DNA sequences to conduct in-depth analysis and find a cure for the procrastination.

Problem Statement

There are $N$ different types of viruses in the JSOI kingdom, and the DNA sequence of each virus is represented by a sequence of uppercase letters.

JYY wants to divide these viruses into the minimum possible number of categories, such that each virus belongs to exactly one category.

Viruses in the same category must satisfy at least one of the following two properties:

  1. The "$k$-prefix" (the first $k$ uppercase letters) of all DNA sequences in the same category are identical;
  2. The "$k$-suffix" (the last $k$ uppercase letters) of all DNA sequences in the same category are identical.

JYY wants to find a classification scheme that satisfies these requirements and minimizes the total number of categories.

Input

The first line contains two positive integers $N$ and $k$.

The next $N$ lines each contain a string $S_i$, representing the DNA sequence of the $i$-th virus. It is guaranteed that the length of $S_i$ is at least $k$.

Output

The first line contains an integer $C$, representing the minimum number of categories.

The next $C$ lines each start with a positive integer $w$, representing the number of viruses in the current category, followed by $w$ positive integers representing the indices of the viruses belonging to that category.

If there are multiple optimal solutions, you may output any one of them.

Scoring

For each test case, if the first line contains the correct positive integer $C$, you will receive 5 points.

If, given that the first line is correct, the following $C$ lines describe a valid optimal solution, you will receive 10 points.

Otherwise, you will receive 0 points.

Examples

Input 1

4 1
A
AB
BB
BA

Output 1

2
2 1 2
2 3 4

Note 1

The sample output receives 10 points.

Constraints

For $20\%$ of the data, $N \le 10$.

For $40\%$ of the data, $N \le 500$.

For $100\%$ of the data, $N \le 5\,000$, $k \le 550$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.