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 ...
随机推荐
- Environment中有大量访问目录的函数
public class Environment { /** * Return root of the "system" partition holding the core An ...
- 在 c#中 如何 重新激活一个控件
比如toolBar是一个组合控件 this.toolBar.CaptionHeight =this.toolBar.Items.Count * 60;//重新激活toolBar控件 CaptionHe ...
- file.seek()
语法:fileObject.seek(offset,whence) offset -- 开始的偏移量,也就是代表需要移动偏移的字节数 whence:可选,默认值为 0.给offset参数一个定义,表示 ...
- matlab遗传算法工具箱
转自http://blog.sina.com.cn/s/blog_5ebcc0240101pnrj.html matlab遗传算法工具箱函数及实例讲解 (2014-01-10 13:03:57) ...
- Python 源码分析:queue 队列模块
起步 queue 模块提供适用于多线程编程的先进先出(FIFO)数据结构.因为它是线程安全的,所以多个线程很轻松地使用同一个实例. 源码分析 先从初始化的函数来看: 从这初始化函数能得到哪些信息呢?首 ...
- Beta冲刺提交-星期五
Beta冲刺提交-星期五 这个作业属于哪个课程 软件工程 这个作业要求在哪里 <作业要求的链接> 团队名称 唱跳RAP编程 这个作业的目标 1.进行每日例会,每个成员汇报自己今天完成 ...
- 获取汉字首字母,拼音,可实现拼音字母搜索----npm js-pinyin
npm install js-pinyin main.js 引入 import pinyin from 'js-pinyin' 使用组件内 let pinyin = require('js- ...
- note for git
1.download https://git-for-windows.github.io/ 2.command add file to git: git add filename & git ...
- css float属性详解
定义和用法 float 属性定义元素在哪个方向浮动.以往这个属性总应用于图像,使文本围绕在图像周围,不过在 CSS 中,任何元素都可以浮动.浮动元素会生成一个块级框,而不论它本身是何种元素.如果浮动非 ...
- LNMP环境搭建网站
系统:Centos7.4 一台服务器安装nginx.php.mysql 原理不是很懂,但实测如下两种环境下都能成功,这里做下记录: 1.一个干净的系统,从0开始完成所有步骤,完成LNMP搭建 2.已经 ...