結果

問題 No.1433 Two color sequence
ユーザー racsosaberacsosabe
提出日時 2021-03-19 22:25:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 166,036 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 17:29:44
合計ジャッジ時間 2,994 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 20 ms
5,376 KB
testcase_04 AC 20 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 29 ms
5,376 KB
testcase_09 AC 33 ms
5,376 KB
testcase_10 AC 31 ms
5,376 KB
testcase_11 AC 32 ms
5,376 KB
testcase_12 AC 33 ms
5,376 KB
testcase_13 AC 33 ms
5,376 KB
testcase_14 AC 29 ms
5,376 KB
testcase_15 AC 30 ms
5,376 KB
testcase_16 AC 29 ms
5,376 KB
testcase_17 AC 29 ms
5,376 KB
testcase_18 AC 30 ms
5,376 KB
testcase_19 AC 31 ms
5,376 KB
testcase_20 AC 31 ms
5,376 KB
testcase_21 AC 31 ms
5,376 KB
testcase_22 AC 31 ms
5,376 KB
testcase_23 AC 32 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int N = 200000 + 5;

int n;
int a[N];
char s[N];

long long solve(){
	long long ans = LLONG_MIN;
	long long mini = 0;
	long long prefix = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R') prefix += a[i];
		else prefix -= a[i];
		ans = max(ans, prefix - mini);
		mini = min(mini, prefix);
	}
	return abs(ans);
}

int main(){
	scanf("%d", &n);
	scanf("%s", s);
	for(int i = 0; i < n; i++) scanf("%d", a + i);
	long long ans1 = solve();
	for(int i = 0; i < n; i++){
		if(s[i] == 'R') s[i] = 'B';
		else s[i] = 'R';
	}
	long long ans2 = solve();
	printf("%lld\n", max(ans1, ans2));
	return 0;
}
0