結果

問題 No.1433 Two color sequence
ユーザー boutarouboutarou
提出日時 2021-03-19 22:07:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 3,791 ms
コンパイル使用メモリ 262,352 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-29 17:02:22
合計ジャッジ時間 5,403 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 14 ms
6,656 KB
testcase_04 AC 14 ms
6,784 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 26 ms
6,656 KB
testcase_09 AC 26 ms
6,656 KB
testcase_10 AC 26 ms
6,400 KB
testcase_11 AC 26 ms
6,528 KB
testcase_12 AC 27 ms
6,656 KB
testcase_13 AC 27 ms
6,528 KB
testcase_14 AC 26 ms
6,656 KB
testcase_15 AC 26 ms
6,528 KB
testcase_16 AC 26 ms
6,656 KB
testcase_17 AC 25 ms
6,784 KB
testcase_18 AC 26 ms
6,528 KB
testcase_19 AC 25 ms
6,528 KB
testcase_20 AC 26 ms
6,656 KB
testcase_21 AC 25 ms
6,528 KB
testcase_22 AC 26 ms
6,656 KB
testcase_23 AC 25 ms
6,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(int i = 0; i < int(n); i++)
using ll = long long;
using P = pair<int, int>;

// 10
// RRBBRBBRBR
// 6 -7 0 8 -1 -2 6 4 -9 -1
// 6 -1 -1 7 6 4 10 14 5 4

    int
    main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n;
    string s;
    cin >> n >> s;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) if(s[i] == 'B') a[i] *= -1;
    vector<ll> sum(n + 1, 0);
    rep(i, n) sum[i + 1] = sum[i] + a[i];
    const ll INF = 1e18;
    ll ma = -INF, mi = INF;
    rep(i, n + 1) {
        ma = max(ma, sum[i]);
        mi = min(mi, sum[i]);
    }
    cout << ma - mi << endl;
    return 0;
}
0