0
点赞
收藏
分享

微信扫一扫

Educational Codeforces Round 123 (Rated for Div. 2) E. Expand the Path

你的益达233 2022-03-18 阅读 28
c++

自己没想出来 参考了大佬们的博客 添加链接描述

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int t,n;string s;
int32_t main(){
    cin>>t;
    while(t--){
        cin>>n>>s;
        int m=s.size();
        int pos=1,x=0,y=0;
        while(pos<m&&s[pos]==s[pos-1]) pos++;
        if(pos==m) {
            cout<<n<<endl;
            continue;
        }
        for(int i=pos;i<m;i++){
            if(s[i]=='R') x++;
            else y++;
        }
        // cout<<x<<" "<<y<<endl;
        int ans=n*n;
        ans=ans-x*y-pos*(n-1);
        cout<<ans<<endl;
    }
}
举报

相关推荐

0 条评论