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