結果

問題 No.1433 Two color sequence
ユーザー SAAD AHMADSAAD AHMAD
提出日時 2022-07-05 05:36:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 490 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 164,924 KB
実行使用メモリ 6,816 KB
最終ジャッジ日時 2023-08-21 16:14:08
合計ジャッジ時間 5,862 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 37 ms
6,644 KB
testcase_04 AC 36 ms
6,548 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 88 ms
6,600 KB
testcase_09 AC 86 ms
6,608 KB
testcase_10 AC 83 ms
6,532 KB
testcase_11 AC 83 ms
6,480 KB
testcase_12 AC 86 ms
6,620 KB
testcase_13 AC 85 ms
6,744 KB
testcase_14 AC 87 ms
6,608 KB
testcase_15 AC 86 ms
6,548 KB
testcase_16 AC 87 ms
6,624 KB
testcase_17 AC 86 ms
6,604 KB
testcase_18 AC 87 ms
6,792 KB
testcase_19 AC 87 ms
6,592 KB
testcase_20 AC 87 ms
6,708 KB
testcase_21 AC 87 ms
6,584 KB
testcase_22 AC 87 ms
6,816 KB
testcase_23 AC 87 ms
6,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ll a[200005];
ll b[200005];

int main(){
  int n; cin >> n;
  string s; cin >> s;
  for(int i = 0; i < n; i++){
    ll num; cin >> num;
    if(s[i] == 'R') a[i] = num;
    else a[i] = -num;
  }
  b[0] = 0;
  for(int i = 0; i < n; i++) b[i+1] = b[i] + a[i];
  ll M = -1e18;
  ll m = 1e18;
  for(int i = 0; i <= n; i++){
    M = max(M, b[i]);
    m = min(m, b[i]);
  }
  ll ans = M - m;
  cout << ans << endl;
  return 0;
}
0