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 ...
随机推荐
- Linux命令(009) -- tar
tar命令可以为Linux的文件和目录创建档案(备份).利用该命令,可以为某一特定文件创建备份,也可以在档案中改变文件或向档案中加入新的文件:可以把一大堆的文件和目录全部打包成一个文件,这对于备份文件 ...
- 原创 SqlParameter 事务 批量数据插入
不错,很好,以后防注入批量事务提交虽然麻烦点研究了几个小时,但不会是问题了 SqlCommand cmd; HelpSqlServer helps = new HelpSqlServer(); //定 ...
- P1062 数列
题目描述 给定一个正整数k(3≤k≤15),把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列,例如,当k=3时,这个序列是: 1,3,4,9,10,12,13,… (该序列实际上就是 ...
- 黑马程序员----java基础:多线程
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ---- ...
- WindowsService+Quartz.NET快速搭建
新建一个Windows服务项目 nuget安装Quartz.NET,我这边使用的是2.3.3版本 1. Service改名 2. 添加安装程序,改名 3. ServiceInstaller->属 ...
- (转)淘淘商城系列——dubbo监控中心
http://blog.csdn.net/yerenyuan_pku/article/details/72777623 之前我们就已学过了dubbo,想必大家对dubbo的架构有所了解,dubbo的架 ...
- 编写图形界面下的Java Swing程序,接受用户输入的两个数据为上下限,然后输出上、下限之间的所有素数。(结果部分每行显示10个数据)
这个代码我整体写的比较简单,读者可以简单参考一下,对人家题目要求略微修改了一下,多加了一个“置空”按钮.下图为我设计的界面 运行程序后的截图请看我后面的截图: package com.wangshil ...
- Linux之基础命令——文件操作
ls(显示指定工作目录下的内容) -a 显示所有文件及目录 包括隐藏文件 -l 除文件名称外,还会将文件类型.权限.拥有者.文件大小等信息详细列出[可以ll简写] -r 将文件以相反次序显示(默认是a ...
- webgl推荐书籍
网址:https://www.douban.com/doulist/45940373/ webgl 来自: Pasu2017-04-17创建 2017-07-25更新 推荐 关注 2 人关注 ...
- HTTP的工作原理
客户机与服务器建立连接后,发送一个请求给服务器,请求格式为:统一资源标识符.协议版本号.服务器收到请求的信息(包括请求行,请求头,请求体).服务器接收到请求后,给予相应的响应信息,格式为一个状态行(包 ...