CF451D.Count Good Substrings

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".

Given a string, you have to find two values:

  1. the number of good substrings of even length;
  2. the number of good substrings of odd length.

输入格式

The first line of the input contains a single string of length nn ( 1<=n<=1051<=n<=10^{5} ). Each character of the string will be either 'a' or 'b'.

输出格式

Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length.

输入输出样例

  • 输入#1

    bb
    

    输出#1

    1 2
    
  • 输入#2

    baab
    

    输出#2

    2 4
    
  • 输入#3

    babb
    

    输出#3

    2 5
    
  • 输入#4

    babaa
    

    输出#4

    2 7
    

说明/提示

In example 1, there are three good substrings ("b", "b", and "bb"). One of them has even length and two of them have odd length.

In example 2, there are six good substrings (i.e. "b", "a", "a", "b", "aa", "baab"). Two of them have even length and four of them have odd length.

In example 3, there are seven good substrings (i.e. "b", "a", "b", "b", "bb", "bab", "babb"). Two of them have even length and five of them have odd length.

Definitions

A substring s[l,r]s[l,r] (1<=l<=r<=n)(1<=l<=r<=n) of string s=s1s2... sns=s_{1}s_{2}...\ s_{n} is string slsl+1... srs_{l}s_{l+1}...\ s_{r} .

A string s=s1s2... sns=s_{1}s_{2}...\ s_{n} is a palindrome if it is equal to string snsn1... s1s_{n}s_{n-1}...\ s_{1} .

首页