Hdu 4763 Theme Section (simple KMP)

Source: Internet
Author: User

Hdu 4763 Theme Section (simple KMP)

Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1184 Accepted Submission (s): 621


Problem DescriptionIt's time for music! A lot of popular musicians are invited to join us in the music festival. each of them will play one of their representative songs. to make the programs more interesting and challenging, the hosts are going to add some constraints to the rhythm of the songs, I. e ., each song is required to have a 'Theme section '. the theme section shall be played at the beginning, the middle, and the end of each song. more specifically, given a theme section E, the song will be in the format of 'eaebe', where section A and section B cocould have arbitrary number of notes. note that there are 26 types of notes, denoted by lower case letters 'a'-'Z '.

To get well prepared for the festival, the hosts want to know the maximum possible length of the theme section of each song. Can you help us?

InputThe integer N in the first line denotes the total number of songs in the festival. each of the following N lines consists of one string, indicating the notes of the I-th (1 <= I <= N) song. the length of the string will not exceed 10 ^ 6.
OutputThere will be N lines in the output, where the I-th line denotes the maximum possible length of the theme section of the I-th song.

Sample Input
5xyabcaaaaaaabaaaxoaaaaa

Sample Output
00112

Source2013 ACM/ICPC Asia Regional Changchun Online

Given a string, search for three strings to make them completely equal (not overlapped). One must start from the beginning and the other must end with the end.


# Include "stdio. h "# include" string. h "# define N 1000005 char str [N], s [N]; int next [N], n; void getnext (int m) {int I = 0, j =-1; next [0] =-1; while (I
 
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.