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 ...
随机推荐
- uwp选取文件夹并读取其中的图片
uwp对文件的操作和wpf,winform等等有很大的不同,主要原因是uwp对权限的要求比较严格,不能想从前那样随心所欲的读取文件. 1.首先找到Package.appxmanifest这个文件,在功 ...
- Linux oraenv Tips
Linux for the Oracle DBA -Customizing the Oracle User's Environment There are many ways to customize ...
- 222 Count Complete Tree Nodes 完全二叉树的节点个数
给出一个完全二叉树,求出该树的节点个数.完全二叉树的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置.若最底层为第 h ...
- Kali linux 2016.2(Rolling) 的详细安装(图文教程)附安装VMare Tools 增强工具
写在前面的话 因读研期间,实验室团队需要,所以,接触上了Kali Linux,需去获得网络安全方面的数据,即数据和信息收集.以便为后续的数据处理和分析,准备! 用到hadoop和spark.机器学习等 ...
- vue.js学习参考手册
参考手册 示例:www.51siyuan.cn/161.html
- Java MVC框架性能比较
Java MVC框架性能比较 - by zvane 现在各种MVC框架很多,各框架的优缺点网络上也有很多的参考文章,但介绍各框架性能方面差别的文章却不多,本人在项目开发中,感觉到采用了struts2框 ...
- Node.js——body方式提交数据
引入核心模块 http,利用其 api(http.createServer) 返回一个 http.server 实例,这个实例是继承于net.Server,net.Server 也是通过net.cre ...
- CentOS 7 挂载ntfs磁盘格式的U盘
因为CentOS 默认不识别NTFS的磁盘格式,所以我们要借助另外一个软件来挂载,那就是ntfs-3g了 自带的yum源没有这个软件,要用第三方的软件源,这里我用的是阿里的epel. 1. 切换到系统 ...
- spring mvc介绍只试图解析(转载)
转载路径 http://haohaoxuexi.iteye.com/blog/1770554 SpringMVC视图解析器 前言 在前一篇博客中讲了SpringMVC的Controller控制器,在这 ...
- MySql(一)mysql服务的基本操作及环境配置
MySQL服务的启动开始–>计算机–>右键选择管理–>双击打开服务和应用程序–>双击服务–>找到MySQL的服务名称(我的是MySQL56),右键选择启动即可 通过命令行 ...