結果
| 問題 | No.3061 Cut and Maximums |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-10 17:55:02 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 1,351 bytes |
| 記録 | |
| コンパイル時間 | 1,299 ms |
| コンパイル使用メモリ | 215,144 KB |
| 実行使用メモリ | 35,740 KB |
| 最終ジャッジ日時 | 2026-05-10 17:55:09 |
| 合計ジャッジ時間 | 3,759 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#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\n",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<<max(1,slv(slv,st[1]))<<'\n';
return 0;
}