結果

問題 No.1433 Two color sequence
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-04-05 13:06:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 172,656 KB
最終ジャッジ日時 2023-08-29 02:19:37
合計ジャッジ時間 7,279 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,456 KB
testcase_01 AC 66 ms
71,164 KB
testcase_02 AC 66 ms
71,296 KB
testcase_03 AC 221 ms
164,248 KB
testcase_04 AC 188 ms
163,912 KB
testcase_05 AC 66 ms
71,376 KB
testcase_06 AC 69 ms
71,392 KB
testcase_07 AC 81 ms
71,616 KB
testcase_08 AC 173 ms
172,656 KB
testcase_09 AC 189 ms
172,064 KB
testcase_10 AC 189 ms
170,608 KB
testcase_11 AC 190 ms
171,364 KB
testcase_12 AC 195 ms
171,556 KB
testcase_13 AC 195 ms
172,080 KB
testcase_14 AC 192 ms
172,220 KB
testcase_15 AC 185 ms
172,392 KB
testcase_16 AC 188 ms
171,980 KB
testcase_17 AC 191 ms
172,008 KB
testcase_18 AC 184 ms
172,376 KB
testcase_19 AC 188 ms
172,020 KB
testcase_20 AC 186 ms
172,368 KB
testcase_21 AC 195 ms
172,344 KB
testcase_22 AC 188 ms
172,228 KB
testcase_23 AC 188 ms
172,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main1(n,s,a):
    ans=-float('inf')
    """
    |R-B|=max(R-B,B-R)
    """
    b=[ai if si=='R' else -ai for ai,si in zip(a,s)]
    # bの連続部分列和の最大
    sb=[0]
    for x in b:sb.append(sb[-1]+x)
    m=0
    for x in sb[1:]:
        ans=max(ans,x-m)
        m=min(m,x)
    b=[-ai if si=='R' else ai for ai,si in zip(a,s)]
    # bの連続部分列和の最大
    sb=[0]
    for x in b:sb.append(sb[-1]+x)
    m=0
    for x in sb[1:]:
        ans=max(ans,x-m)
        m=min(m,x)
    return ans

if __name__=='__main__':
    n=int(input())
    s=list(input())
    a=list(map(int,input().split()))
    print(main1(n,s,a))
0