結果

問題 No.1433 Two color sequence
ユーザー sten_sansten_san
提出日時 2021-03-19 21:58:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,698 bytes
コンパイル時間 2,064 ms
コンパイル使用メモリ 202,632 KB
実行使用メモリ 7,444 KB
最終ジャッジ日時 2023-08-12 02:06:50
合計ジャッジ時間 4,060 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 16 ms
7,420 KB
testcase_04 AC 16 ms
7,320 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 28 ms
7,304 KB
testcase_09 AC 30 ms
7,076 KB
testcase_10 AC 28 ms
7,172 KB
testcase_11 AC 29 ms
7,088 KB
testcase_12 AC 30 ms
7,172 KB
testcase_13 AC 30 ms
7,156 KB
testcase_14 AC 29 ms
7,400 KB
testcase_15 AC 29 ms
7,356 KB
testcase_16 AC 29 ms
7,332 KB
testcase_17 AC 29 ms
7,436 KB
testcase_18 AC 29 ms
7,320 KB
testcase_19 AC 29 ms
7,320 KB
testcase_20 AC 28 ms
7,444 KB
testcase_21 AC 29 ms
7,328 KB
testcase_22 AC 28 ms
7,396 KB
testcase_23 AC 29 ms
7,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr); cout.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

int main() {
    constexpr int64_t inf = INT64_MAX/ 4;

    int n; cin >> n;
    string s; cin >> s;
    auto a = vec<int>(uns, n);
    for (auto &e : a) cin >> e;

    auto acc1 = vec<int64_t>(uns, n + 1);
    auto acc2 = vec<int64_t>(uns, n + 1);
    acc1[0] = acc2[0] = 0;

    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') {
            acc1[i + 1] = acc1[i] + a[i];
            acc2[i + 1] = acc2[i] - a[i];
        }
        if (s[i] == 'B') {
            acc1[i + 1] = acc1[i] - a[i];
            acc2[i + 1] = acc2[i] + a[i];
        }
    }

    int64_t ans = -inf;

    int64_t min1 = 0, min2 = 0;
    for (int i = 1; i <= n; ++i) {
        ans = max({
            ans,
            acc1[i] - min1,
            acc2[i] - min2,
        });

        min1 = min(min1, acc1[i]);
        min2 = min(min2, acc2[i]);
    }

    cout << ans << endl;
}

0