C. Plasticine zebra

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.

Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.

Before assembling the zebra Grisha can make the following operation 00 or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".

Determine the maximum possible length of the zebra that Grisha can produce.

Input

The only line contains a string ss (1≤|s|≤1051≤|s|≤105, where |s||s| denotes the length of the string ss) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.

Output

Print a single integer — the maximum possible zebra length.

Examples

input

Copy

bwwwbwwbw

output

Copy

5

input

Copy

bwwbwwb

output

Copy

3

Note

In the first example one of the possible sequence of operations is bwwwbww|bw →→ w|wbwwwbwb →→ wbwbwwwbw, that gives the answer equal to 55.

In the second example no operation can increase the answer.

同时翻转其实相当于把字符串看成是首尾连接的环

所以先把字符串后面接一个与自己一样的字符串

从头到尾【原字符串】枚举最长的长度 当然不可以超过原字符串的长度

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std; const int maxn = 1e5 + 5;
string s; int main()
{
while(cin>>s){
s += s;
int maxlen = 0;
for(int i = 0; i < s.length() / 2; ){
char now = s[i];
for(int j = i + 1; j - i <= s.length() / 2; j++){
if(s[j] != now){
now = s[j];
if(j - i == s.length() / 2){
maxlen = max(maxlen, j - i);
}
}
else{
maxlen = max(maxlen, j - i);
i = j;
break;
}
}
if(maxlen == s.length() / 2){
break;
}
} printf("%d\n", maxlen);
}
return 0;
}

codeforces#505--C Plasticine Zebra的更多相关文章

  1. CF1025C Plasticine zebra 思维 字符串

    Plasticine zebra time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)-C. Plasticine zebra

    问了学长,感觉还是很迷啊,不过懂了个大概,这个翻转操作,实质不就是在序列后面加上前面部分比如 bw | wwbwwbw  操作过后 wbwbwwbww 而 bw | wwbwwbwbw 这样我们就知道 ...

  3. Codeforces #505(div1+div2) C Plasticine zebra

    题意:给你一段字符串,可以选择任意多的位置,每个位置会反转两边的字符串,问交错的字符串最长是多长? 思路:找规律,仔细分析样例1.假设位置为 1 2 3 4 5 6 7 8 9,反转之后会发现答案是7 ...

  4. CF 1025C Plasticine zebra

    昨晚忘记判只有一个字符的情况fst了呜呜呜 挺有趣的题,昨晚连刚带猜弄出结论 考虑答案的取值,最优答案可能是一个后缀,或者是一个前缀,或者是一个后缀加上前缀 那么翻转之后最优答案的可选值就有了1的前缀 ...

  5. Codeforces 505 A Mr. Kitayuta's Gift【暴力】

    题意:给出一个字符串,可以向该字符串的任意位置插入一个字母使其变成回文串 因为字符串的长度小于10,枚举插入的字母,和要插入的位置,再判断是否已经满足回文串 #include<iostream& ...

  6. CF1025C Plasticine zebra【环状字符串/思维】

    给你一个长度为 \(\left|s\right|\) 的01串 \(s\) ,每次操作你可以任选一个 \(k\) ,使01串的 \([1,k]\) 和 \((k,\left|s\right|]\) 分 ...

  7. Codeforces #505(div1+div2) D Recovering BST

    题意:给你一个升序的数组,元素之间如果gcd不为1可以建边,让你判断是否可以建成一颗二叉搜索树. 解法:dp,首先建图,然后进行状态转移.因为如果点k左端与i相连,右端与k相连,则i和k可以相连,同时 ...

  8. Codeforces #505(div1+div2) B Weakened Common Divisor

    题意:给你若干个数对,每个数对中可以选择一个个元素,问是否存在一种选择,使得这些数的GCD大于1? 思路:可以把每个数对的元素乘起来,然后求gcd,这样可以直接把所有元素中可能的GCD求出来,从小到大 ...

  9. CF C. Plasticine zebra (思维)

    题意: 是输入一个只有'w','b'的字符串,可以对他的任意位置切割成两个子串,切割后的右边的子串翻转后再和左边的子串拼起来会得到一个新的字符串,操作次数不限,问能得到的字符串中wb交替出现的最大的长 ...

随机推荐

  1. android activity lifecycle

    学习android的activity,之前一直没有去琢磨,今天正好了解一下activity生命周期. 参考链接: https://developer.android.com/guide/compone ...

  2. ubuntu配置apache和cgi

    ubuntu配置apache和cgi . 更新源并进行安装,否则后面的下载可能会不成功. sudo apt-get update sudo apt-get upgrade . 安装apache2服务 ...

  3. 第二百九十七节,python操作redis缓存-List类型,可以理解为列表

    python操作redis缓存-List类型,可以理解为列表,是可以有重复元素的列表 List操作,redis中的List在在内存中按照一个name对应一个List来存储.如图: lpush(name ...

  4. 基于mvcpager的分页(get请求,刷新页面),提供两种样式(来自bootstrap的样式)

    使用方法:先把mvcpager.dll引用加入mvc项目 下载路径在本文末尾 前台代码 前台: @{ Layout = null; } @using Webdiyer.WebControls.Mvc ...

  5. kafka学习之-配置详解

    # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreement ...

  6. Yii2自带验证码实现

    总共分为三个方面:控制器配置.模型rules配置和视图配置. 第一步:控制器配置 将下列代码配置在actions中,请求验证码链接对应为 “控制器/captcha” 'captcha' => [ ...

  7. ubuntu下vim配置(刷题和比赛两套)

    1. 平时刷题练习使用 "mswin.vim 插件提供windows下的编辑快捷键功能 source $VIMRUNTIME/mswin.vim behave mswin set nu se ...

  8. Effective C++ Item 15 Provide access to raw resources in resource-managing classes

    In last two item, I talk about resource-managing using RAII, now comes to the practical part. Often, ...

  9. ionic creator(ionic生成器)

    用来生成前端 html 还是挺方便的(接口数据另算),弄好就可以直接下载 https://creator.ionic.io/app/dashboard/projects

  10. rpm源码安装mysql

    1)访问官网(mysql社区服务器) http://downloads.mysql.com/archives/community/ 2)选择自己需要的版本和对应服务器(例如 服务器是centos 6. ...