結果

問題 No.1433 Two color sequence
ユーザー qingmuyusiqingmuyusi
提出日時 2021-03-19 22:38:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 3,257 bytes
コンパイル時間 1,684 ms
コンパイル使用メモリ 168,152 KB
実行使用メモリ 5,228 KB
最終ジャッジ日時 2023-08-12 03:19:31
合計ジャッジ時間 4,986 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 35 ms
5,080 KB
testcase_04 AC 35 ms
5,020 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,388 KB
testcase_08 AC 87 ms
5,096 KB
testcase_09 AC 86 ms
4,952 KB
testcase_10 AC 82 ms
4,772 KB
testcase_11 AC 83 ms
4,764 KB
testcase_12 AC 84 ms
4,944 KB
testcase_13 AC 85 ms
5,028 KB
testcase_14 AC 85 ms
5,084 KB
testcase_15 AC 86 ms
5,120 KB
testcase_16 AC 85 ms
5,228 KB
testcase_17 AC 84 ms
5,012 KB
testcase_18 AC 84 ms
5,096 KB
testcase_19 AC 85 ms
5,220 KB
testcase_20 AC 86 ms
5,080 KB
testcase_21 AC 86 ms
5,112 KB
testcase_22 AC 85 ms
5,024 KB
testcase_23 AC 86 ms
4,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include<atcoder/all>
// using namespace atcoder;
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
//---------------------------------------------------------------------------------------------------

int main(void){
    // Your code here!
    int n; cin >> n;
    string s; cin >> s;
    vll a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) {
        if (s[i] == 'B') a[i] = -a[i];
    }
    ll ans = 0;
    int right = 0;
    ll sum = 0;
    rep(left,n) {
        while(right < n && sum + a[right] >= 0) {
            sum += a[right];
            ans = max(ans,sum);
            right++;
        }
        ans = max(ans,sum);

        if (right == left) ++right;
        else sum -= a[left];
    }
    rep(i,n) a[i] = -a[i];
    right = 0;
    sum = 0;
    rep(left,n) {
        while(right < n && sum + a[right] >= 0) {
            sum += a[right];
            ans = max(ans,sum);
            right++;
        }
        ans = max(ans,sum);

        if (right == left) ++right;
        else sum -= a[left];
    }
    // rep(i,n) {
    //     if (now >= 0) {
    //         if (a[i] == 0) continue;
    //         if (a[i] > 0) {
    //             now+= a[i];
    //         } else {
    //             ans = max(ans,now);
    //             now = a[i];
    //         }
    //     } else {
    //         if (a[i] == 0) continue;
    //         if (a[i] < 0) {
    //             now+= a[i];
    //         } else {
    //             ans = max(ans,-now);
    //             now = a[i];
    //         }
    //     }
    // }
    cout << ans << endl;
}
0