結果

問題 No.1433 Two color sequence
ユーザー itohdakitohdak
提出日時 2021-03-19 21:52:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 2,495 ms
コンパイル使用メモリ 206,552 KB
実行使用メモリ 15,952 KB
最終ジャッジ日時 2023-08-12 01:57:05
合計ジャッジ時間 5,382 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 17 ms
6,640 KB
testcase_04 AC 17 ms
6,552 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 86 ms
15,844 KB
testcase_09 AC 80 ms
15,492 KB
testcase_10 AC 78 ms
14,996 KB
testcase_11 AC 83 ms
15,320 KB
testcase_12 AC 85 ms
15,548 KB
testcase_13 AC 79 ms
15,576 KB
testcase_14 AC 91 ms
15,800 KB
testcase_15 AC 87 ms
15,800 KB
testcase_16 AC 89 ms
15,880 KB
testcase_17 AC 81 ms
15,840 KB
testcase_18 AC 84 ms
15,816 KB
testcase_19 AC 80 ms
15,744 KB
testcase_20 AC 94 ms
15,908 KB
testcase_21 AC 83 ms
15,792 KB
testcase_22 AC 83 ms
15,952 KB
testcase_23 AC 88 ms
15,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  vector<ll> sum(n+1); rep(i, n) sum[i+1] = sum[i] + (s[i] == 'R' ? A[i] : -A[i]);
  ll ans = 0;
  set<ll> st;
  rep(i, n+1) {
    if(i) {
      chmax(ans, abs(sum[i]-*st.begin()));
      chmax(ans, abs(sum[i]-*st.rbegin()));
    }
    st.insert(sum[i]);
  }
  cout << ans << endk;
  return 0;
}
0