結果

問題 No.1433 Two color sequence
ユーザー ebi_flyebi_fly
提出日時 2021-03-20 13:29:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 770 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 78,272 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-04-30 23:45:52
合計ジャッジ時間 3,570 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 37 ms
9,856 KB
testcase_04 AC 37 ms
9,856 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 87 ms
9,984 KB
testcase_09 AC 87 ms
9,856 KB
testcase_10 AC 81 ms
9,472 KB
testcase_11 AC 82 ms
9,728 KB
testcase_12 AC 89 ms
9,728 KB
testcase_13 AC 85 ms
9,856 KB
testcase_14 AC 85 ms
9,856 KB
testcase_15 AC 83 ms
9,728 KB
testcase_16 AC 84 ms
9,984 KB
testcase_17 AC 83 ms
9,856 KB
testcase_18 AC 83 ms
9,856 KB
testcase_19 AC 84 ms
9,856 KB
testcase_20 AC 83 ms
9,984 KB
testcase_21 AC 86 ms
9,856 KB
testcase_22 AC 88 ms
9,856 KB
testcase_23 AC 84 ms
9,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)

using i64 = std::int64_t;

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

int main() {
	int n;
	std::string s;
	std::cin >> n >> s;
	std::vector<i64> a(n);
	std::vector<i64> sum(n+1,0);
	std::vector<i64> max(n+1,0), min(n+1,0);
	rep(i,0,n) {
		std::cin >> a[i];
		if(s[i] == 'B') a[i] *= -1;
		sum[i+1] = sum[i] + a[i];
		max[i+1] = std::max(max[i], sum[i]);
		min[i+1] = std::min(min[i], sum[i]);
	}
	i64 ans = -1;
	rep(i,0,n) {
		chmax(ans, std::abs(sum[i+1]-max[i+1]));
		chmax(ans, std::abs(sum[i+1]-min[i+1]));
	}
	std::cout << ans << '\n';
}
0