結果

問題 No.1433 Two color sequence
ユーザー 👑 CleyLCleyL
提出日時 2021-03-19 22:02:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 2,079 bytes
コンパイル時間 978 ms
コンパイル使用メモリ 94,596 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-18 22:23:07
合計ジャッジ時間 2,481 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

//author:luckYrat(twitter:@luckYrat_)
//
//https://www.youtube.com/watch?v=z_B9iJ8r4ic
//
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <cctype>
#include <utility>
#include <climits>
//
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);
//
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)
//
#define pb push_back
#define fir first
#define scn second
#define ednl endl
//
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")
//n
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
cout << fixed << setprecision(n) << //n
min(max)_element(iter,iter)()
count(iter,iter,int)intiteriter
*/
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main(){
int n;cin>>n;
string s;cin>>s;
ll a[n];
for(int i = 0; n > i; i++){
cin>>a[i];
if(s[i] == 'B'){
a[i]*=-1;
}
}
//+
ll nw = 0;
ll ans = 0;
for(int i = 0; n > i; i++){
nw += a[i];
if(nw < 0)nw = 0;
ans = max(ans,nw);
}
for(int i = 0; n > i; i++){
nw += a[i];
if(nw > 0)nw = 0;
ans = max(ans,nw*-1);
}
cout << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0