結果

問題 No.1433 Two color sequence
ユーザー bonKotsubonKotsu
提出日時 2021-05-05 00:15:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 167,184 KB
実行使用メモリ 9,656 KB
最終ジャッジ日時 2023-10-01 01:35:53
合計ジャッジ時間 5,696 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 40 ms
9,484 KB
testcase_04 AC 41 ms
9,492 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 92 ms
9,484 KB
testcase_09 AC 90 ms
9,608 KB
testcase_10 AC 87 ms
9,164 KB
testcase_11 AC 88 ms
9,604 KB
testcase_12 AC 90 ms
9,604 KB
testcase_13 AC 90 ms
9,528 KB
testcase_14 AC 90 ms
9,428 KB
testcase_15 AC 91 ms
9,496 KB
testcase_16 AC 91 ms
9,544 KB
testcase_17 AC 90 ms
9,564 KB
testcase_18 AC 91 ms
9,656 KB
testcase_19 AC 91 ms
9,508 KB
testcase_20 AC 91 ms
9,492 KB
testcase_21 AC 92 ms
9,488 KB
testcase_22 AC 91 ms
9,568 KB
testcase_23 AC 91 ms
9,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

const ll INF = 1e18;
int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<ll> x(n), sum(n+1), mx(n+1), mn(n+1);
  rep(i, n) {
    cin >> x[i];
    if (s[i] == 'B') x[i] *= -1;
  }
  rep(i, n) sum[i+1] = sum[i] + x[i];
  rep(i, n) {
    mx[i+1] = max(mx[i], sum[i+1]);
    mn[i+1] = min(mn[i], sum[i+1]);
  }
  ll ans = -1e18;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, sum[i]-mn[i]);
    ans = max(ans, abs(sum[i]-mx[i]));
  }
  cout << ans << endl;



}
0