A9478 | Count Good Substrings
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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:
1. the number of good substrings of even length;
2. the number of good substrings of odd length.
Given a string, you have to find two values:
1. the number of good substrings of even length;
2. the number of good substrings of odd length.
输入格式
The first line of the input contains a single string of length $n$ ( $1<=n<=10^{5}$ ). 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.
输入输出样例
输入 #1
bb
输出 #1
1 2
输入 #2
baab
输出 #2
2 4
输入 #3
babb
输出 #3
2 5
输入 #4
babaa
输出 #4
2 7
In example 1, there are three good substrings ("b", "b", and "bb"). One of them has even length and two of them have odd length.
In example 2, there are six good substrings (i.e. "b", "a", "a", "b", "aa", "baab"). Two of them have even length and four of them have odd length.
In example 3, there are seven good substrings (i.e. "b", "a", "b", "b", "bb", "bab", "babb"). Two of them have even length and five of them have odd length.
Definitions
A substring $s[l,r]$ $(1<=l<=r<=n)$ of string $s=s_{1}s_{2}...\ s_{n}$ is string $s_{l}s_{l+1}...\ s_{r}$ .
A string $s=s_{1}s_{2}...\ s_{n}$ is a palindrome if it is equal to string $s_{n}s_{n-1}...\ s_{1}$ .
In example 2, there are six good substrings (i.e. "b", "a", "a", "b", "aa", "baab"). Two of them have even length and four of them have odd length.
In example 3, there are seven good substrings (i.e. "b", "a", "b", "b", "bb", "bab", "babb"). Two of them have even length and five of them have odd length.
Definitions
A substring $s[l,r]$ $(1<=l<=r<=n)$ of string $s=s_{1}s_{2}...\ s_{n}$ is string $s_{l}s_{l+1}...\ s_{r}$ .
A string $s=s_{1}s_{2}...\ s_{n}$ is a palindrome if it is equal to string $s_{n}s_{n-1}...\ s_{1}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted