結果

問題 No.1433 Two color sequence
ユーザー hir355hir355
提出日時 2021-03-19 21:49:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 378 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 106,756 KB
最終ジャッジ日時 2023-08-12 01:48:33
合計ジャッジ時間 4,721 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,492 KB
testcase_01 AC 72 ms
71,268 KB
testcase_02 AC 73 ms
71,184 KB
testcase_03 AC 124 ms
106,756 KB
testcase_04 AC 116 ms
106,456 KB
testcase_05 AC 71 ms
71,320 KB
testcase_06 AC 72 ms
71,320 KB
testcase_07 AC 72 ms
71,456 KB
testcase_08 AC 136 ms
104,696 KB
testcase_09 AC 143 ms
103,616 KB
testcase_10 AC 138 ms
101,496 KB
testcase_11 AC 139 ms
101,496 KB
testcase_12 AC 144 ms
103,656 KB
testcase_13 AC 141 ms
103,432 KB
testcase_14 AC 139 ms
103,624 KB
testcase_15 AC 135 ms
103,480 KB
testcase_16 AC 133 ms
103,588 KB
testcase_17 AC 139 ms
103,668 KB
testcase_18 AC 138 ms
103,664 KB
testcase_19 AC 141 ms
103,456 KB
testcase_20 AC 138 ms
103,336 KB
testcase_21 AC 140 ms
103,536 KB
testcase_22 AC 157 ms
103,676 KB
testcase_23 AC 142 ms
103,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()
a = list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(n):
    if s[i] == 'R':
        b[i + 1] = b[i] + a[i]
    else:
        b[i + 1] = b[i] - a[i]
ans = 0
m = 0
for i in range(n):
    m = min(m, b[i + 1])
    ans = max(ans, b[i + 1] - m)
m = 0
for i in range(n):
    m = max(m, b[i + 1])
    ans = max(ans, m - b[i + 1])
print(ans)
0