CF877B.Nikita and string

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One day Nikita found the string containing letters "a" and "b" only.

Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".

Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?

一天,尼基塔发现了一个仅由字母 “a” 和 “b” 构成的字符串。

尼基塔认为,若一个字符串能被(不改变字母顺序地)分割成 3 个子串(每个子串可以为空),且第 1 个和第 3 个子串仅包含字母 “a”,第 2 个子串仅包含字母 “b”,则该字符串是优美的。

尼基塔希望通过删除该字符串中的一些字符(也可以不删),但不改变剩余字符的相对顺序,来使字符串变得优美。他能得到的优美字符串的最大长度是多少?

输入格式

The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".

第一行包含一个非空字符串,长度不超过 5 000,且仅由小写英文字母 “a” 和 “b” 组成。

输出格式

Print a single integer — the maximum possible size of beautiful string Nikita can get.

输出一个整数——Nikita 能得到的优美字符串的最大可能长度。

输入输出样例

  • 输入#1

    abba

    输出#1

    4
  • 输入#2

    bab

    输出#2

    2

说明/提示

It the first sample the string is already beautiful.

In the second sample he needs to delete one of "b" to make it beautiful.

在第一个样例中,该字符串已经是优美的。

在第二个样例中,他需要删除一个字符 "b" 以使其变得优美。

输入解题思路,AI测评打分。不知道怎么写?

首页