CF1082B.Vova and Trophies
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vova has won n trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row.
The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement as beautiful as possible — that means, to maximize the length of the longest such subsegment.
Help Vova! Tell him the maximum possible beauty of the arrangement if he is allowed to do at most one swap.
沃瓦在不同的比赛中赢得了 n 个奖杯。每个奖杯要么是金色的,要么是银色的。这些奖杯排成一排。
该排列的“美观度”定义为由金色奖杯构成的最长连续子段的长度。沃瓦希望交换两个奖杯(不一定是相邻的)以使排列尽可能美观——即最大化该最长连续子段的长度。
请帮助沃瓦!告诉他:若最多允许进行一次交换,该排列可能达到的最大美观度是多少?
输入格式
The first line contains one integer n (2≤n≤105) — the number of trophies.
The second line contains n characters, each of them is either G or S. If the i-th character is G, then the i-th trophy is a golden one, otherwise it's a silver trophy.
第一行包含一个整数 n(2≤n≤105)—— 奖杯的数量。
第二行包含 n 个字符,每个字符为 G 或 S。若第 i 个字符为 G,则第 i 个奖杯为金质奖杯;否则为银质奖杯。
输出格式
Print the maximum possible length of a subsegment of golden trophies, if Vova is allowed to do at most one swap.
输出在最多进行一次交换的前提下,金色奖杯子段的最大可能长度。
输入输出样例
输入#1
10 GGGSGGGSGG
输出#1
7
输入#2
4 GGGG
输出#2
4
输入#3
3 SSS
输出#3
0
说明/提示
In the first example Vova has to swap trophies with indices 4 and 10. Thus he will obtain the sequence "GGGGGGGSGS", the length of the longest subsegment of golden trophies is 7.
In the second example Vova can make no swaps at all. The length of the longest subsegment of golden trophies in the sequence is 4.
In the third example Vova cannot do anything to make the length of the longest subsegment of golden trophies in the sequence greater than 0.
在第一个例子中,沃瓦必须交换索引为 4 和 10 的奖杯。这样他将得到序列 "GGGGGGGSGS",其中金色奖杯的最长连续子段长度为 7。
在第二个例子中,沃瓦可以完全不进行任何交换。该序列中金色奖杯的最长连续子段长度为 4。
在第三个例子中,沃瓦无法采取任何操作,使得序列中金色奖杯的最长连续子段长度大于 0。
输入解题思路,AI测评打分。不知道怎么写?