跳到正文

个人记录

TRAMPOLIN

1232RvE约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int n,k,h[N],lf[N],rt[N],maxn[N];
char t[N];

int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",h+i);
    scanf("%s",t+1);//从第一位
    for(int i=2;i<=n;i++){
		if(h[i]>=h[i-1]){
        	if(t[i-1]=='T')t[i]='T';
        	lf[i]=lf[i-1]+1;
    	}
	}
    for(int i=n-1;i>=1;i--){
		if(h[i]>=h[i+1]){
        	if(t[i+1]=='T')t[i]='T';
        	rt[i]=rt[i+1]+1;
    	}
	}
    int T=0,maxn=-1;
    for(int i=1;i<=n;i++)
        if(t[i]=='T')++T;//TT互跳
        else maxn=max(maxn,max(lf[i],rt[i])+1);//要么一直向左,要么一直向右
    if(t[k]=='T'){
		printf("%d\n",T+maxn);
    	return 0;
	}
    int l=k,r=k;
    while(l>1&&h[l-1]==h[k])l--;
    while(r<n&&h[r+1]==h[k])r++;
    printf("%d\n",r-l+1+max(lf[l],rt[r]));
    return 0;
}
原文