結果

問題 No.1433 Two color sequence
ユーザー shotoyooshotoyoo
提出日時 2021-03-19 21:52:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 530 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 129,152 KB
最終ジャッジ日時 2024-04-29 16:39:01
合計ジャッジ時間 4,222 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
51,840 KB
testcase_01 AC 42 ms
51,712 KB
testcase_02 AC 42 ms
51,968 KB
testcase_03 AC 120 ms
122,496 KB
testcase_04 AC 114 ms
129,152 KB
testcase_05 AC 42 ms
51,584 KB
testcase_06 AC 42 ms
51,712 KB
testcase_07 AC 41 ms
52,096 KB
testcase_08 AC 132 ms
126,736 KB
testcase_09 AC 151 ms
127,120 KB
testcase_10 AC 145 ms
125,936 KB
testcase_11 AC 143 ms
126,232 KB
testcase_12 AC 146 ms
126,740 KB
testcase_13 AC 148 ms
127,004 KB
testcase_14 AC 140 ms
126,508 KB
testcase_15 AC 141 ms
126,380 KB
testcase_16 AC 138 ms
126,632 KB
testcase_17 AC 146 ms
126,500 KB
testcase_18 AC 143 ms
126,628 KB
testcase_19 AC 149 ms
126,620 KB
testcase_20 AC 139 ms
126,372 KB
testcase_21 AC 145 ms
126,624 KB
testcase_22 AC 147 ms
126,628 KB
testcase_23 AC 146 ms
126,368 KB
権限があれば一括ダウンロードができます

ソースコード

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