結果
| 問題 | No.1433 Two color sequence | 
| コンテスト | |
| ユーザー |  noritake | 
| 提出日時 | 2021-04-01 09:42:12 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 104 ms / 2,000 ms | 
| コード長 | 1,945 bytes | 
| コンパイル時間 | 1,888 ms | 
| コンパイル使用メモリ | 196,252 KB | 
| 最終ジャッジ日時 | 2025-01-20 04:54:55 | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
#include <bits/stdc++.h>
// #include <atcoder/all> // NOTE: AtCoderライブラリ
using namespace std;
// using namespace atcoder; // NOTE: AtCoderライブラリ
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define dbg3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;
#define nl() cout << "========================================" << endl;
#define yn { puts("Yes"); } else{ puts("No"); } // 使い方: if (条件) yn; 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<long long, long long>> vpll;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }
int main() {
    int N; cin >> N;
    string S; cin >> S;
    vl A(N); rep(i, N) cin >> A[i];
    rep(i, N) {
        if (S[i] == 'B') A[i] *= -1;
    }
    ll res = -LINF;
    vl dp(N);
    dp[0] = A[0];
    chmax(res, dp[0]);
    for (int i = 1; i < N; i++) {
        dp[i] = max(A[i], dp[i - 1] + A[i]);
        chmax(res, dp[i]);
    }
    rep(i, N) A[i] *= -1;
    vl dp2(N);
    dp2[0] = A[0];
    chmax(res, dp2[0]);
    for (int i = 1; i < N; i++) {
        dp2[i] = max(A[i], dp2[i - 1] + A[i]);
        chmax(res, dp2[i]);
    }
    cout << res << endl;
}
            
            
            
        