結果

問題 No.3061 Cut and Maximums
コンテスト
ユーザー BOT
提出日時 2026-05-10 17:52:30
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,342 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,351 ms
コンパイル使用メモリ 215,172 KB
実行使用メモリ 35,740 KB
最終ジャッジ日時 2026-05-10 17:52:37
合計ジャッジ時間 6,019 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pi=pair<int,int>;
#define fi first
#define se second
template<typename T>void debug(char *s,T x){cerr<<s<<" = "<<x<<'\n';}
template<typename T,typename ...Ar>void debug(char*s,T x,Ar...y) {
    int dep=0;
    while(*s!=','||dep)dep+=(*s=='('?1:*s==')'?-1:0),cerr<<*s++;
    cerr<<" = "<<x<<", ",debug(s+1,y...);
}
#define gdb(...) debug((char*)#__VA_ARGS__,__VA_ARGS__)
const int N=3e5+5;
int n,st[N],a[N],b[N],ls[N],rs[N];
string s;
int main() {
    #ifndef ONLINE_JUDGE
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
    #endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    cin>>s;
    int cb=count(s.begin(),s.end(),'B');
    if(cb&&s[n-1]=='W')cout<<"-1",exit(0);
    if(!cb)cout<<"0\n",exit(0);
    int p=max_element(a+1,a+n+1)-a,top=0;
    for(int i=p%n+1;i!=p;i=i%n+1) {
        b[++b[0]]=a[i];
        int t0=top;
        while(top&&a[i]>b[st[top]])top--;
        if(top)rs[st[top]]=b[0];
        if(top<t0)ls[b[0]]=st[top+1];
        st[++top]=b[0];
    }
    auto slv=[&](auto&&_,int x) {
        if(!x)return 0;
        if(s[b[x]-1]=='W')return _(_,ls[x])+_(_,rs[x]);
        return max({1,_(_,ls[x]),_(_,rs[x])});
    };
    cout<<slv(slv,st[1])<<'\n';
    return 0;
}
0