結果

問題 No.1433 Two color sequence
ユーザー shotoyooshotoyoo
提出日時 2021-03-19 21:52:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 530 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,636 KB
実行使用メモリ 129,024 KB
最終ジャッジ日時 2024-11-18 22:00:55
合計ジャッジ時間 3,887 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")

n = int(input())
s = input()
a = list(map(int, input().split()))
dp0 = [0]
dp1 = [0]
ans = -float("inf")
for i in range(n):
    v0 = max(dp0[-1], 0)
    v1 = max(dp1[-1], 0)
    v = a[i]
    if s[i]=="R":
        v0 += v
        v1 -= v
    else:
        v0 -= v
        v1 += v
    dp0.append(v0)
    dp1.append(v1)
    ans=max(ans,v0,v1)
print(ans)
0