HDU 4821 Hangzhou Field Competition: hash and comparison of each segment string

Source: Internet
Author: User
Tags bitset

HDU 4821 Hangzhou Field Competition: hash and comparison of each segment string

I-String Time Limit:1000 MS Memory Limit:32768KB 64bit IO Format:% I64d & % I64uSubmit Status Practice HDU 4821

Description

Given a string S and two integers L and M, we consider a substring of S as "recoverable" if and only if
(I) It is of length M * L;
(Ii) It can be constructed by concatenating M "diversified" substrings of S, where each of these substrings has length L; two strings are considered as "diversified" if they don't have the same character for every position.

Two substrings of S are considered as "different" if they are cut from different part of S. for example, string "aa" has 3 different substrings "aa", "a" and "".

Your task is to calculate the number of different "recoverable" substrings of S.

Input

The input contains multiple test cases, proceeding to the End of File.

The first line of each test case has two space-separated integers M and L.

The second ine of each test case has a string S, which consists of only lowercase letters.

The length of S is not larger than 10 ^ 5, and 1 ≤ M * L ≤ the length of S.

Output

For each test case, output the answer in a single line.

Sample Input

 3 3abcabcbcaabc 

Sample Output

 2 

Idea: It's a pity that this question was not made during the weekly competition. If we remember that unsigned long would automatically take the modulo and remind the emperor, maybe the Emperor would be able to do it. Alas, he got a lot of Modulo and finally WA. It's too unwise. Fan teased.

I hash the question from the front, and it is uncomfortable to see that the question is hashed from the back, so I hash it from the front. They are all the same.

#include
 
  #include
  
   #include
   
    #include#include
    #include
     
      #include
      
       #include
       
        #define INF 100007using namespace std;typedef long long ll;typedef unsigned long long ull;char s[100005];ull base[100010],hash[100010];int main(){ int m,l,i,j;//system("pause"); for(i=1,base[0]=1;i<100001;i++) base[i]=base[i-1]*131ULL; while(~scanf("%d%d",&m,&l)) { map
        
         mm; scanf("%s",s); int sum=0,len=strlen(s); for(i=1,hash[0]=0;i<=len;i++) hash[i]=hash[i-1]*131+s[i-1]-'a'+1; for(i=0;i
         
          

Related Article

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.