A12199 | Vova and Trophies
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains one integer $n$ ( $2 \le n \le 10^5$ ) — 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.
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.
输出格式
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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted