結果

問題 No.1433 Two color sequence
ユーザー milanis48663220milanis48663220
提出日時 2021-03-19 22:03:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,323 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 97,864 KB
実行使用メモリ 8,300 KB
最終ジャッジ日時 2023-08-12 02:15:54
合計ジャッジ時間 3,132 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 20 ms
8,300 KB
testcase_04 AC 20 ms
8,292 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 34 ms
8,288 KB
testcase_09 AC 35 ms
8,184 KB
testcase_10 AC 34 ms
7,848 KB
testcase_11 AC 34 ms
8,108 KB
testcase_12 AC 35 ms
8,300 KB
testcase_13 AC 35 ms
8,224 KB
testcase_14 AC 34 ms
8,288 KB
testcase_15 AC 34 ms
8,260 KB
testcase_16 AC 34 ms
8,144 KB
testcase_17 AC 35 ms
8,296 KB
testcase_18 AC 34 ms
8,156 KB
testcase_19 AC 34 ms
8,200 KB
testcase_20 AC 35 ms
8,144 KB
testcase_21 AC 34 ms
8,252 KB
testcase_22 AC 34 ms
8,156 KB
testcase_23 AC 35 ms
8,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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; }

using namespace std;
typedef long long ll;

ll calc(string s, vector<ll> a){
    int n = a.size();
    vector<ll> cumsum(n+1);
    for(int i = 0; i < n; i++){
        if(s[i] == 'R') cumsum[i+1] = cumsum[i]+a[i];
        else if(s[i] == 'B') cumsum[i+1] = cumsum[i]-a[i];
    }
    ll ans = 0;
    ll cur = 0;
    
    for(int i = 1; i <= n; i++){
        chmax(ans, cumsum[i]-cur);
        chmin(cur, cumsum[i]);
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    string s; cin >> s;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll ans1 = calc(s, a);
    for(int i = 0; i < n; i++) a[i] = -a[i];
    ll ans2 = calc(s, a);
    cout << max(ans1, ans2) << endl;
}
0