結果
| 問題 |
No.1433 Two color sequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-19 21:59:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 939 bytes |
| コンパイル時間 | 756 ms |
| コンパイル使用メモリ | 83,452 KB |
| 実行使用メモリ | 8,192 KB |
| 最終ジャッジ日時 | 2024-11-18 22:15:32 |
| 合計ジャッジ時間 | 2,443 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#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;
}