LA 4513 hash denotes string suffix

Source: Internet
Author: User

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&itemid=8&page=show_problem& category=&problem=2514&mosmsg=submission+received+with+id+1623942

Dr. Ellie Arroway have established contact with an extraterrestrial civilization. However, all efforts to decode their messages has failed so far because, as luck would has it, they has stumbled upon a Race of Stuttering aliens! Her team had found out that, in every long enough message, the most important words appear repeated a certain number of TI Mes as a sequence of consecutive characters, even in the middle of other words. Furthermore, sometimes they use contractions in an obscure manner. For example, if they need to sayBabtwice, they might just send the messageBabab, which has been abbreviated because the secondbOf the first Word can be reused as the firstbOf the second one.

Thus, the message contains possibly overlapping repetitions of the same words over and over again. As a result, Ellie turns to you, S.R. Hadden, for help in identifying the gist of the message.

Given an integerm, and a strings, representing the message, your task is to find the longest substring ofsThat appears at leastmTimes. For example, in the messageBaaaababababbababbab, the length-5WordBababis contained3times, namely at positions5,7and A(where indices start at zero). No substring appearing3The or more times are longer (see the first example from the sample input). On the other hand, no substring appears OneTimes or more (see example2).

In case there was several solutions, the substring with the rightmost occurrence was preferred (see example3).

InputThe input contains several test cases. Each test case consists of a line with an integer m ( m1), the minimum number of repetitions, followed by a line containing a string sof length between m and About, inclusive. All characters in sis lowercase characters from "a" to "Z". The last test case was denoted by m = 0and must not being processed.

OutputPrint one line of output for each test case. If There is no solution, outputNone; otherwise, print integers in a line, separated by a space. The first integer denotes the maximum length of a substring appearing at least mTimes ; the second integer gives the rightmost possible starting position of such a substring.

Sample Input
3baaaababababbababbab11baaaababababbababbab3cccccc0

Sample Output
5 12none4 2
/**uvala 4513 Hash (petition P225) Topic: There is a stuttering alien, when speaking contains a lot of repeating string, give the alien said a word, find at least m times the longest string, if there is the output length and the maximum value of the starting position of the string problem solving ideas: Two-point answer L, and then determine if there is a string of length l that appears at least m times. The method of judging is simple, from left to right, calculates the hash value of the string with the length of l at all starting positions, and once the hash value appears at least m times there is a solution.          It is worth mentioning that when you are two minutes, pay attention to the satisfying conditions of the processing loop. * * #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm>using namespace Std;typedef unsigned long long ll;const int maxn=40000+10;const int hashseed=31;int n,m,pos; LL Hash[maxn];///hash[i] represents the hash value of the string whose length is L, starting with I, LL seed[maxn],has[maxn];///is the power of the seed, the latter is the hash value of the suffix with the beginning of I, int r[maxn];int cmp ( Const int& A,const int& b) {return hash[a]

LA 4513 hash denotes string suffix

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.