303094: CF603A. Alternative Thinking
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Alternative Thinking
题意翻译
## 题意简述 现有一个长度为 $n$ 的 01 串, 可以进行一次区间翻转 ( 起点终点随意, 并且区间里的值 1 变 0, 0 变 1 ), 得到一个新的 01 串, 使得得到的新的 01 串中的一个子串最长 (子串不一定连续), 且这个子串是 01 间隔的,没有连续两个字符相同。比如 `0101` , `101` 和`1010` 是合法的, `100`, `1100` 是不合法的。试求翻转后最长 01 间隔子串的长度. ## 样例1的解释 Kevin可以把串 100**00**011 中加粗的部分翻转, 使其成为 100**11**011, 这样这个串中最长的 01 间隔子串为 **10**0**1**1**01**1 , 长度为5. Translated by @星烁晶熠辉题目描述
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length $ n $ . Each character of Kevin's string represents Kevin's score on one of the $ n $ questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, $ {0,1,0,1} $ , $ {1,0,1} $ , and $ {1,0,1,0} $ are alternating sequences, while $ {1,0,0} $ and $ {0,1,0,1,1} $ are not. Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.输入输出格式
输入格式
The first line contains the number of questions on the olympiad $ n $ ( $ 1<=n<=100000 $ ). The following line contains a binary string of length $ n $ representing Kevin's results on the USAICO.
输出格式
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
输入输出样例
输入样例 #1
8
10000011
输出样例 #1
5
输入样例 #2
2
01
输出样例 #2
2