結果

問題 No.1433 Two color sequence
ユーザー okok
提出日時 2021-03-19 21:59:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 82,272 KB
実行使用メモリ 8,356 KB
最終ジャッジ日時 2023-08-12 02:08:05
合計ジャッジ時間 2,679 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 18 ms
8,220 KB
testcase_04 AC 17 ms
8,132 KB
testcase_05 AC 2 ms
4,512 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 31 ms
8,192 KB
testcase_09 AC 32 ms
7,880 KB
testcase_10 AC 32 ms
7,976 KB
testcase_11 AC 31 ms
7,908 KB
testcase_12 AC 32 ms
7,988 KB
testcase_13 AC 32 ms
7,924 KB
testcase_14 AC 31 ms
8,132 KB
testcase_15 AC 31 ms
8,184 KB
testcase_16 AC 32 ms
8,252 KB
testcase_17 AC 30 ms
8,236 KB
testcase_18 AC 31 ms
8,356 KB
testcase_19 AC 30 ms
8,240 KB
testcase_20 AC 32 ms
8,144 KB
testcase_21 AC 31 ms
8,192 KB
testcase_22 AC 32 ms
8,128 KB
testcase_23 AC 30 ms
8,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


int solve(string &S, vector<int> a, char c){
	int N = S.size();
	int maxi = -INF, b = -INF;
	
	for(int i = 0; i < N; i++){
		if(c == S[i]) {
			a[i] *= -1;
		}
	}
	
	for(int i = 0; i < N; i++){
		b = max(a[i], b + a[i]);
		maxi = max(maxi, b);
		// cout<<a[i]<<" "<<maxi<<" "<<b<<endl;
	}
	// cout<<endl;
	
	return maxi;
}
signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
	string S;
	vector<int> a;
	
	cin>>N;
	
	cin>>S;
	
	a.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
	}
	
	cout<<max(solve(S, a, 'R'),solve(S, a, 'B'))<<endl;
	
	return 0;
}
0