A1246 | [COCI-2011_2012-olympiad]#4 TRAMPOLIN
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
There are many action superheroes out there: Batman, Spiderman, Superman, Icantwriteman etc.
Among them, there is one gentleman called Kickass. Today he wants to mimic Spiderman, so he has chosen a row of tall skyscrapers to jump around on.
Specifically, he has chosen a sequence of N skyscrapers numbered 1 through N from left to right. He is initially located on the K th skyscraper. Unfortunately, Kickass has very limited powers, and can therefore jump only to the adjacent skyscraper to the left or right, and only if that skyscraper's height is not greater than the height of the skyscraper he is currently on. However, anticipating this and not wanting to look weak, he has positioned trampolines on top of some skyscrapers, and from these skyscrapers he can jump onto any other skyscraper, no matter how tall or where that skyscraper is.
Find the maximum number of different skyscrapers Kickass can visit in a chain of jumps starting from the skyscraper numbered K. If a skyscraper is visited more than once, we still count it only once.
Moreover, skyscraper K is counted even if we never return to it.
Among them, there is one gentleman called Kickass. Today he wants to mimic Spiderman, so he has chosen a row of tall skyscrapers to jump around on.
Specifically, he has chosen a sequence of N skyscrapers numbered 1 through N from left to right. He is initially located on the K th skyscraper. Unfortunately, Kickass has very limited powers, and can therefore jump only to the adjacent skyscraper to the left or right, and only if that skyscraper's height is not greater than the height of the skyscraper he is currently on. However, anticipating this and not wanting to look weak, he has positioned trampolines on top of some skyscrapers, and from these skyscrapers he can jump onto any other skyscraper, no matter how tall or where that skyscraper is.
Find the maximum number of different skyscrapers Kickass can visit in a chain of jumps starting from the skyscraper numbered K. If a skyscraper is visited more than once, we still count it only once.
Moreover, skyscraper K is counted even if we never return to it.
输入格式
The first line of input contains the two integers N and K (3 ≤ N ≤ 300 000, 1 ≤ K ≤ N), the total number of skyscrapers and the starting skyscraper, respectively.
The second line of input contains N integers less than 10^6, the heights of skyscrapers in order from left to right.
The third line of input contains a sequence of N characters '.' or 'T'. If the i th character is 'T', then there is a trampoline positioned on the top of skyscraper i.
The second line of input contains N integers less than 10^6, the heights of skyscrapers in order from left to right.
The third line of input contains a sequence of N characters '.' or 'T'. If the i th character is 'T', then there is a trampoline positioned on the top of skyscraper i.
输出格式
The first and only line of output must contain the required maximum number of visited skyscrapers.
输入输出样例
输入 #1
6 4 12 16 16 16 14 14 .T....
输出 #1
5
输入 #2
10 1 10 7 3 1 1 9 8 2 4 10 ..T..T....
输出 #2
7
Second sample description: the sequence of visited skyscrapers could be the following:
1 2 3 6 10 9 8.
1 2 3 6 10 9 8.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted