結果
| 問題 | No.1433 Two color sequence | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-03-19 22:07:27 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 29 ms / 2,000 ms | 
| コード長 | 739 bytes | 
| コンパイル時間 | 4,048 ms | 
| コンパイル使用メモリ | 250,212 KB | 
| 最終ジャッジ日時 | 2025-01-19 18:33:29 | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
#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;
}
            
            
            
        