#P1604. Cyclic Cipher
Cyclic Cipher
Cyclic Cipher
题面翻译
给定 个数列,第 个数列包含 个不超过 的互不相同的正整数(从 开始标号)。
每一秒将每个数列中的数左移一个位置(即将每个数的下标 , 下标 的数下标变为 ), 并记录由每个数列的第一个数组成的序列。
秒过后,对于所有的 ,求 在记录下来的序列中出现的最长的连续的一段长度。
题目描述
You are given sequences. Each sequence consists of positive integers, not exceeding . All integers in one sequence are distinct, but the same integer may appear in multiple sequences. The length of the -th sequence is .
Each second integers in each of the sequences are shifted by one to the left, i.e. integers at positions i>1 go to positions , while the first integers becomes the last.
Each second we take the first integer of each sequence and write it down to a new array. Then, for each value from to we compute the longest segment of the array consisting of element only.
The above operation is performed for seconds. For each integer from to find out the longest segment found at this time.
输入格式
The first line of the input contains two integers and ( ) — the number of sequences and the maximum integer that can appear in the sequences.
Then follow lines providing the sequences. Each of them starts with an integer ( ) — the number of integers in the sequence, proceeded by positive integers — elements of the sequence. It's guaranteed that all integers in each sequence are pairwise distinct and do not exceed .
The total length of all sequences doesn't exceed .
输出格式
Print integers, the -th of them should be equal to the length of the longest segment of the array with all its values equal to during the first seconds.
样例 #1
样例输入 #1
3 4
3 3 4 1
4 1 3 4 2
3 3 1 4
样例输出 #1
2
1
3
2
样例 #2
样例输入 #2
5 5
2 3 1
4 5 1 3 2
4 2 1 3 5
1 3
2 5 3
样例输出 #2
3
1
4
0
1
样例 #3
样例输入 #3
4 6
3 4 5 3
2 6 3
2 3 6
3 3 6 5
样例输出 #3
0
0
2
1
1
2