結果

問題 No.1433 Two color sequence
ユーザー noya2
提出日時 2020-12-15 22:51:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 195,068 KB
最終ジャッジ日時 2025-01-17 01:15:11
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;
const ll inf = 1e18;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<ll> ar(n);
    rep(i,n) cin >> ar[i];
    rep(i,n) if (s[i] == 'B') ar[i] *= -1LL;
    vector<ll> rui(n+1,0LL);
    repp(i,n+1,1) rui[i] = rui[i-1] + ar[i-1];
    vector<ll> ma(n+1,0LL);
    repp(i,n+1,1) ma[i] = max(ma[i-1],rui[i]);
    vector<ll> mi(n+1,0LL);
    repp(i,n+1,1) mi[i] = min(mi[i-1],rui[i]);
    ll mans = -inf;
    repp(i,n+1,1){
        mans = max(mans,rui[i] - mi[i-1]);
    }
    ll mins = inf;
    repp(i,n+1,1){
        mins = min(mins,rui[i] - ma[i-1]);
    }
    cout << max(abs(mans),abs(mins)) << endl;
}
0