結果

問題 No.1433 Two color sequence
ユーザー あかりきあかりき
提出日時 2021-03-20 01:47:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 380 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 171,320 KB
最終ジャッジ日時 2024-04-29 21:29:18
合計ジャッジ時間 5,142 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
51,712 KB
testcase_01 AC 40 ms
51,840 KB
testcase_02 AC 40 ms
52,096 KB
testcase_03 AC 162 ms
164,024 KB
testcase_04 AC 158 ms
164,280 KB
testcase_05 AC 40 ms
51,840 KB
testcase_06 AC 40 ms
51,840 KB
testcase_07 AC 41 ms
52,096 KB
testcase_08 AC 166 ms
171,136 KB
testcase_09 AC 173 ms
171,056 KB
testcase_10 AC 172 ms
169,272 KB
testcase_11 AC 174 ms
169,732 KB
testcase_12 AC 173 ms
170,928 KB
testcase_13 AC 174 ms
170,932 KB
testcase_14 AC 173 ms
170,420 KB
testcase_15 AC 173 ms
170,476 KB
testcase_16 AC 172 ms
171,240 KB
testcase_17 AC 173 ms
170,936 KB
testcase_18 AC 172 ms
170,684 KB
testcase_19 AC 172 ms
170,476 KB
testcase_20 AC 170 ms
170,816 KB
testcase_21 AC 172 ms
171,076 KB
testcase_22 AC 173 ms
171,320 KB
testcase_23 AC 174 ms
170,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
s=list(input())
a=list(map(int,input().split()))

L1=[]
L2=[]
for i in range(n):
  if s[i]=='R':
    L1.append(a[i])
    L2.append(-a[i])
  else:
    L1.append(-a[i])
    L2.append(a[i])

ans1=[]
ans2=[]
ct1=0
ct2=0
for i in range(n):
  ct1+=L1[i]
  if ct1<0:
    ct1=0
  ans1.append(ct1)
  ct2+=L2[i]
  if ct2<0:
    ct2=0
  ans2.append(ct2)

print(max(ans1+ans2))
0