結果

問題 No.1433 Two color sequence
ユーザー ocvret_
提出日時 2021-03-19 21:50:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 170,808 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-18 21:51:59
合計ジャッジ時間 3,778 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


//連続する区間和の最大値
ll kadane(vector<ll> &v){
  ll res = -1e18;
  ll s = 0;
  rep(i,v.size()){
    s = max(s+v[i],v[i]);
    res = max(res,s);
  }
  return res;
}

int main(){
  
  int n;
  string s;
  cin >> n >> s;
  vector<ll> a(n);
  rep(i,n)cin >> a[i];
  rep(i,n)if(s[i] == 'B')a[i] *= (-1);
  ll res = kadane(a);
  rep(i,n)a[i] *= (-1);
  res = max(res,kadane(a));
  cout << res << "\n";


  return 0;
}
0