Codeforces Round #258 (Div. 2) D
2 seconds
256 megabytes
standard input
standard output
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.
The first line of the input contains a single string of length n (1 ≤ n ≤ 105). 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.
bb
1 2
baab
2 4
babb
2 5
babaa
2 7
sl :分析发现最后回文串的第一个字符和第二个字符相同,这样统计相应数位上的字符就行了。
1 //by caonima
2 //hehe
3 #include <bits/stdc++.h>
4 typedef long long LL;
5 const int MAX = 1e5+;
6 char str[MAX];
7 LL even_cnt[],odd_cnt[];
8 // odd ji even o
9 int main() {
LL odd,even;
while(scanf("%s",str+)==) {
memset(even_cnt,,sizeof(even_cnt));
memset(odd_cnt,,sizeof(odd_cnt));
int n=strlen(str+);
odd=even=;
for(int i=;i<=n;i++) {
int x=str[i]-'a';
if(i&) {
odd+=odd_cnt[x];
even+=even_cnt[x];
odd_cnt[x]++;
}
else {
odd+=even_cnt[x];
even+=odd_cnt[x];
even_cnt[x]++;
}
}
odd+=n;
printf("%I64d %I64d\n",even,odd);
}
return ;
33 }
Codeforces Round #258 (Div. 2) D的更多相关文章
- Codeforces Round #258 (Div. 2)[ABCD]
Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...
- Codeforces Round #258 (Div. 2) 小结
A. Game With Sticks (451A) 水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行.列有一个为0,那么谁就赢了.因为Akshat先选,因此假设行 ...
- Codeforces Round #258 (Div. 2) B. Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...
- Codeforces Round #258 (Div. 2) E. Devu and Flowers 容斥
E. Devu and Flowers 题目连接: http://codeforces.com/contest/451/problem/E Description Devu wants to deco ...
- Codeforces Round #258 (Div. 2) D. Count Good Substrings 水题
D. Count Good Substrings 题目连接: http://codeforces.com/contest/451/problem/D Description We call a str ...
- Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game 水题
C. Predict Outcome of the Game 题目连接: http://codeforces.com/contest/451/problem/C Description There a ...
- Codeforces Round #258 (Div. 2) . Sort the Array 贪心
B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...
- Codeforces Round #258 (Div. 2) A. Game With Sticks 水题
A. Game With Sticks 题目连接: http://codeforces.com/contest/451/problem/A Description After winning gold ...
- Codeforces Round #258 (Div. 2) 容斥+Lucas
题目链接: http://codeforces.com/problemset/problem/451/E E. Devu and Flowers time limit per test4 second ...
- Codeforces Round #258 (Div. 2) D. Count Good Substrings —— 组合数学
题目链接:http://codeforces.com/problemset/problem/451/D D. Count Good Substrings time limit per test 2 s ...
随机推荐
- B - Archer
Problem description SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to ...
- 【转】【开源下载】基于TCP网络通信的即时聊天系统(IM系统)(c#源码)
原文链接 强烈关注,学习!
- 转-UIButton定义和设置圆角
//login button // .h 中定义 UIButton *_loginBtn; @property (strong,nonatomic)UIButton *loginBtn; // .m ...
- yum 安装报错:*epel: mirrors.aliyun.comError: xzcompressionnot available
环境背景:epel源下载地址: http://mirrors.aliyun.com/Centos内核内核版本[root@nfs01 ~]# uname -r2.6.32-642.el6.x86_64= ...
- 什么是BDD?
BDD是TDD的一种衍生,通过特定的BDD框架,用自然语言或类自然语言,按照编写用户故事或者用户用例的方式,以功能使用者的视角,描述并编写测试用例. BDD源于TDD并优于测试驱动开发. 之所以说BD ...
- iOS :Object-C 语言merge两个字典对象
Object-C 语言merge两个字典对象 - (id)mutableDictionaryCopyIfNeeded:(id)dictObj { if ([dictObj isKindOfClass: ...
- Elasticsearch の 查询类型
查询类型SearchType Es中一共有四种查询类型:QUERY_AND_FETCH.QUERY_THEN_FETCH.DFS_QUERY_AND_FETCH.DFS_QUERY_THEN_FETC ...
- 常用css属性拓展
text-overflow:clip | ellipsis(默认值:clip)clip:当内联内容溢出块容器时,将溢出部分裁切掉.ellipsis:当内联内容溢出块容器时,将溢出部分替换为(...). ...
- C++ 多态、虚函数、虚析构函数
1.若某种语言只支持类但不支持多态,则只能称为基于对象,不能说是面向对象. 2.多态:向不同对象发送同一个消息,不同的对象会产生不同的行为,发送消息可以是调用函数等操作.函数重载.运算符重载都是多态. ...
- CSS中常用属性之字体属性
1,以下是CSS中常用字体属性: font-family 字体样式 font-size 字体大小 font-size-adjust 为元素规定 ...