結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,584 KB
testcase_01 AC 42 ms
51,840 KB
testcase_02 AC 40 ms
51,840 KB
testcase_03 AC 122 ms
130,816 KB
testcase_04 AC 119 ms
129,536 KB
testcase_05 AC 41 ms
51,712 KB
testcase_06 AC 41 ms
51,840 KB
testcase_07 AC 40 ms
51,840 KB
testcase_08 AC 137 ms
126,124 KB
testcase_09 AC 152 ms
126,000 KB
testcase_10 AC 150 ms
125,312 KB
testcase_11 AC 155 ms
125,592 KB
testcase_12 AC 154 ms
125,972 KB
testcase_13 AC 154 ms
126,252 KB
testcase_14 AC 152 ms
126,140 KB
testcase_15 AC 152 ms
125,884 KB
testcase_16 AC 151 ms
126,264 KB
testcase_17 AC 155 ms
125,888 KB
testcase_18 AC 157 ms
126,020 KB
testcase_19 AC 151 ms
126,384 KB
testcase_20 AC 151 ms
126,392 KB
testcase_21 AC 153 ms
126,412 KB
testcase_22 AC 155 ms
126,008 KB
testcase_23 AC 154 ms
126,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = str(input())
A = list(map(int,input().split()))
A0 = []; A1= []
for i in range(N):
    if S[i] == "R":
        val0 = A[i]
        val1 = -A[i]
    else:
        val0 = -A[i]
        val1 = A[i]
    A0.append(val0)
    A1.append(val1)
#print(A0,A1)
ans0 = 0
temp0 = 0
store0 = 0
for i in range(N):
    if A0[i] > 0:
        #temp0 += A0[i]
        store0 += A0[i]
    else:
        #temp0 = 0
        store0 += A0[i]
    if store0 < 0:
        store0 = 0
    #print(temp0,store0,A0[i])
    ans0 = max(ans0,store0)
#print(ans0)
    
ans1 = 0
temp1 = 0
store1 = 0
for i in range(N):
    if A1[i] > 0:
        #temp1 += A1[i]
        store1 += A1[i]
    else:
        #temp1 = 0
        store1 += A1[i]
    if store1 < 0:
        store1 = 0
    #print(temp1,store1,A[i])
    ans1 = max(ans1,store1)
#print(ans1)
print(max(ans0,ans1))
0