Codeforces Round #258 (Div. 2) D. Count Good Substrings 水题

D. Count Good Substrings

题目连接:

http://codeforces.com/contest/451/problem/D

Description

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:

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

Input

The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).

Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.

Output

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

Sample Input

bb

Sample Output

1 2

Hint

题意

他定义了一个叫做good串的东西,就是重叠的字符就算作一个,然后如果重叠算一个,且最后是回文串的话,那么他就是好的。

现在给你一个串,问你他的奇数长度good,和偶数长度good各有多少个。

题解:

由于只含有ab,所以这种回文串一定是ababababa这种的,那么只要两端相同就好了。

然后我们统计一下就行。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
char s[maxn];
long long cnt[3][3];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    long long odd=0,even=0;
    for(int i=0;i<len;i++)
    {
        cnt[s[i]-'a'][i%2]++;
        even+=cnt[s[i]-'a'][1-i%2];
        odd+=cnt[s[i]-'a'][i%2];
    }
    printf("%lld %lld\n",even,odd);
}

转载于:https://www.cnblogs.com/qscqesze/p/5856411.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值