「POJ3693」Maximum repetition substring

2015年1月14日6,3352

Description

The repetition number of a string is defined as the maximum number R such that the string can be partitioned into R same consecutive substrings. For example, the repetition number of “ababab” is 3 and “ababa” is 1.

Given a string containing lowercase letters, you are to find a substring of it with maximum repetition number.

Input

The input consists of multiple test cases. Each test case contains exactly one line, which
gives a non-empty string consisting of lowercase letters. The length of the string will not be greater than 100,000.

The last test case is followed by a line containing a ‘#’.

Output

For each test case, print a line containing the test case number( beginning with 1) followed by the substring of maximum repetition number. If there are multiple substrings of maximum repetition number, print the lexicographically smallest one.

Sample Input

Sample Output

题解

先穷举长度L,然后求长度为L 的子串最多能连续出现几次。首先连续出现1 次是肯定可以的,所以这里只考虑至少2 次的情况。假设在原字符串中连续出现2 次,记这个子字符串为S,那么S 肯定包括了字符r[0], r[L], r[L*2],r[L*3], ……中的某相邻的两个。所以只须看字符r[L*i]和r[L*(i+1)]往前和往后各能匹配到多远,记这个总长度为K,那么这里连续出现了K/L+1 次。

以上来自罗穗骞论文

往后匹配多远 r 用ST表求lcp即可。。。往前 l 就把串反过来再做一下。。

但是有可能求出来的最长串可以前移/后移几位
即开头可以在落在\([i-l,i-l+(l+r)mod\ L]\)

区间内字典序最小的还要用ST表找rank区间最值

ps:此题数据很水,发现我代码若有漏洞请留言

 

 

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
cgh Recent comment authors
  Subscribe  
提醒
cgh

好羡慕黄学长的代码总能打的简洁
Orz

trackback

Fifa Coins

Thank you, I’ve just been looking for information approximately this topic for a long time and yours is the greatest I’ve discovered till now. But, what about the conclusion? Are you sure concerning the source?|