CodeForces 451D Count Good Substrings

Source: Internet
Author: User

CodeForces 451D Count Good Substrings

Question:

A string that only contains a and B asks how many "compressed input strings" with an even length and an odd length are compressed into one character.

Ideas:

After the string is compressed, it must meet the following conditions ...... Ababab ...... In this way, as long as the characters at both ends are the same, the number of input strings formed by a as the left endpoint is equal to the number of a on the right. The length is odd or even. it can be judged that if a matches a in an odd position with a in an odd position, the input string is an odd length, or B in an even length. Therefore, a statistical method is obtained. the number of characters on the right of the character that are the same as that on the character that are in the odd and even positions can be calculated to obtain the result.

Code:

#include
 
  #include
  
   #includeusing namespace std;typedef __int64 LL;#define N 100010char str[N];int ch[N];int sum[2][2][N];int n;LL ans[2];int main(){    int i,len,wei;    while(~scanf("%s",str))    {        len=strlen(str);        for(i=0;i
   
    =0;i--)        {            sum[0][0][i]=sum[0][0][i+1];            sum[0][1][i]=sum[0][1][i+1];            sum[1][0][i]=sum[1][0][i+1];            sum[1][1][i]=sum[1][1][i+1];            sum[ch[i+1]][(i+1)%2][i]++;        }        for(i=0;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.