結果

問題 No.1433 Two color sequence
ユーザー yamake
提出日時 2021-03-19 21:59:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 1,744 ms
コンパイル使用メモリ 169,500 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-11-18 22:15:54
合計ジャッジ時間 4,377 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define debug(output) cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;

signed main(){
  int n;cin>>n;
  string s;cin>>s;
  vector<lint> a(n),red(n+1,0),blue(n+1,0);
  rep(i,n)cin>>a[i];
  rep1(i,n){
    red[i]=red[i-1];
    blue[i]=blue[i-1];
    if(s[i-1]=='R')red[i]+=a[i-1];
    else blue[i]+=a[i-1];
  }
  lint res=-linf;
  lint rb=0;lint br=0;
  rep1(i,n){
    lint buf=red[i]-blue[i]-rb;
    buf=max(buf,blue[i]-red[i]-br);
    res=max(res,buf);
    rb=min(rb,red[i]-blue[i]);
    br=min(br,blue[i]-red[i]);
  }
  cout<<res<<"\n";
  return 0;
}
0