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 ...
随机推荐
- ACM_最小公倍数
Lowest Common Multiple Plus Time Limit: 2000/1000ms (Java/Others) Problem Description: 求n个数的最小公倍数. I ...
- performClick()方法的使用
performClick 是使用代码主动去调用控件的点击事件(模拟人手去触摸控件) 例如: 添加Ctrl+s 快捷键 保存,并触发btnSave按钮事件 protected override bool ...
- java数据结构和算法05(二叉树)
对于树这个数据结构,第一次看到这个树肯定是一脸蒙逼,玛德,树?种树的那个树么?哈哈哈,当然不是,前面我们说过数组添加.删除数据很慢,查询数据很快:而链表添加.删除数据很快,但是查找数据很慢,我们就想啊 ...
- 自学 iOS - 三十天三十个 Swift 项目 第三天
做了这个小demo 之后 感觉OC 和swift 还是有很大的差别的 自己还是要去多看些swift的语法 用的不是很熟练 1.这个demo 的资源文件 我都是用原工程的 2.同样的自定义cell 的 ...
- 网盘资源搜索的一些知识 C#
针对互联网盘上的资源进行搜索查找.写一个网盘资源搜索的要点主要有以下几点. 1.这个网盘资源搜索的原理就是利用互联网搜索引擎的site 命令. 其次就是针对网页链接进行提取以及处理. 首先就是编写一个 ...
- jQuery的属性与样式之样式操作.css()
.css() 方法:获取元素样式属性的计算值或者设置元素的CSS属性 获取: .css( propertyName ) :获取匹配元素集合中的第一个元素的样式属性的计算值 .css( property ...
- asterisk-java ami5 分机状态,挂机原因之类的
这些东西网上随便一找一大堆,也只是记录下自己找的.方便以后自己复制粘贴用. 最后为啦实现分机状态在web的实时更新,我选择啦使用websocket. //获得分机状态 public static St ...
- 学习嵌入式开发板的Android平台体系结构和源码结构
本文转自迅为论坛资料:http://www.topeetboard.com 推荐学习嵌入式开发板平台:iTOP-4412开发板 下面这张图出自Google官方,展示了Android系统的主要组成部分. ...
- 部分cocoscreator左右移动代码
cc.Class({extends: cc.Component, properties: { // 主角跳跃高度 jumpHeight: 0, // 主角跳跃持续时间 jumpDuration: 0, ...
- Linux 的 Spinlock 在 MIPS 多核处理器中的设计与实现
引言 随着科技的发展,尤其是在嵌入式领域,高性能.低功耗的处理器成为众多厂商追逐的目标,但是由于技术和工艺的瓶颈,试图在单核处理器上达到这样的目标变得越发困难,于是人们提出了多核处理器的概念.多核处理 ...