結果

問題 No.1433 Two color sequence
ユーザー noya2noya2
提出日時 2020-12-15 22:51:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 2,086 ms
コンパイル使用メモリ 204,808 KB
実行使用メモリ 9,772 KB
最終ジャッジ日時 2023-10-20 09:44:37
合計ジャッジ時間 4,956 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 41 ms
9,772 KB
testcase_04 AC 40 ms
9,772 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 96 ms
9,772 KB
testcase_09 AC 94 ms
9,772 KB
testcase_10 AC 90 ms
9,508 KB
testcase_11 AC 91 ms
9,772 KB
testcase_12 AC 93 ms
9,772 KB
testcase_13 AC 94 ms
9,772 KB
testcase_14 AC 93 ms
9,772 KB
testcase_15 AC 94 ms
9,772 KB
testcase_16 AC 94 ms
9,772 KB
testcase_17 AC 94 ms
9,772 KB
testcase_18 AC 94 ms
9,772 KB
testcase_19 AC 93 ms
9,772 KB
testcase_20 AC 94 ms
9,772 KB
testcase_21 AC 94 ms
9,772 KB
testcase_22 AC 94 ms
9,772 KB
testcase_23 AC 94 ms
9,772 KB
権限があれば一括ダウンロードができます

ソースコード

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