結果

問題 No.1433 Two color sequence
ユーザー ocvret_ocvret_
提出日時 2021-03-19 21:50:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 166,252 KB
実行使用メモリ 5,232 KB
最終ジャッジ日時 2023-08-12 01:50:29
合計ジャッジ時間 4,980 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 34 ms
4,928 KB
testcase_04 AC 34 ms
4,984 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 87 ms
5,088 KB
testcase_09 AC 85 ms
4,944 KB
testcase_10 AC 81 ms
4,780 KB
testcase_11 AC 82 ms
4,784 KB
testcase_12 AC 84 ms
5,044 KB
testcase_13 AC 84 ms
4,928 KB
testcase_14 AC 84 ms
5,232 KB
testcase_15 AC 82 ms
5,052 KB
testcase_16 AC 84 ms
5,048 KB
testcase_17 AC 84 ms
5,016 KB
testcase_18 AC 85 ms
4,928 KB
testcase_19 AC 85 ms
5,232 KB
testcase_20 AC 84 ms
5,048 KB
testcase_21 AC 85 ms
5,040 KB
testcase_22 AC 84 ms
5,044 KB
testcase_23 AC 83 ms
5,044 KB
権限があれば一括ダウンロードができます

ソースコード

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