結果

問題 No.1433 Two color sequence
ユーザー katoru_perfperf
提出日時 2021-03-26 20:20:54
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,004 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 122,240 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-11-28 19:43:47
合計ジャッジ時間 4,506 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <stdio.h>
#include <limits.h>

using namespace std;

long long MINIMUM = LLONG_MIN;

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	vector<long long> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a.at(i);
	}

	for (int i = 0; i < N; i++) {
		if (S.at(i) == 'B') {
			a.at(i) *= (-1);
		}
	}

	vector<long long> plusdp(N);
	vector<long long> minusdp(N);

	plusdp.at(0) = a.at(0);
	minusdp.at(0) = (-1) * a.at(0);

	for (int i = 0; i < N-1; i++) {
		plusdp.at(i + 1) = max(a.at(i+1), plusdp.at(i) + a.at(i+1));
		minusdp.at(i + 1) = max((-1)*a.at(i + 1), minusdp.at(i) - a.at(i + 1));
	}

	/*for (int i = 0; i < N; i++) {
		cout << plusdp.at(i) << " ";
	}
	cout << endl;

	for (int i = 0; i < N; i++) {
		cout << minusdp.at(i) << " ";
	}
	cout << endl;*/

	long long  MAX = MINIMUM;

	for (int i = 0; i < N; i++) {
		if (plusdp.at(i) > MAX) {
			MAX = plusdp.at(i);
		}
		if (minusdp.at(i) > MAX) {
			MAX = minusdp.at(i);
		}
	}

	cout << abs(MAX);
}
0