結果

問題 No.1433 Two color sequence
ユーザー kept1994kept1994
提出日時 2021-08-29 01:00:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,161 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 81,716 KB
実行使用メモリ 157,004 KB
最終ジャッジ日時 2024-05-01 19:09:39
合計ジャッジ時間 5,590 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,612 KB
testcase_01 AC 33 ms
53,280 KB
testcase_02 AC 33 ms
52,584 KB
testcase_03 AC 132 ms
131,548 KB
testcase_04 AC 124 ms
131,360 KB
testcase_05 AC 37 ms
52,600 KB
testcase_06 AC 34 ms
52,400 KB
testcase_07 WA -
testcase_08 AC 142 ms
156,328 KB
testcase_09 WA -
testcase_10 AC 145 ms
155,144 KB
testcase_11 AC 155 ms
155,636 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 146 ms
156,252 KB
testcase_15 WA -
testcase_16 AC 148 ms
156,328 KB
testcase_17 WA -
testcase_18 AC 146 ms
156,492 KB
testcase_19 AC 147 ms
156,484 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 143 ms
156,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys

def main():
    import itertools 
    N = int(input())
    S = input()
    A = list(map(int, input().split()))
    RmB = []
    mRB = []
    for i in range(N):
        if S[i] == "B":
            RmB.append(-A[i])
            mRB.append(A[i])
        else:
            RmB.append(A[i])
            mRB.append(-A[i])
    sRmB = [0] + list(itertools.accumulate(RmB))
    smRB = [0] + list(itertools.accumulate(mRB))
    # print(RmB)
    # print(mRB)
    # print(sRmB)
    # print(smRB)
    minS = 10 ** 10
    maxS = -1 * 10 ** 10
    ans = -1 * 10 ** 10
    for i in range(N + 1):
        # print(sRmB[i], minS)
        if sRmB[i] <= minS:
            ans = max(ans, maxS - minS)
            minS = sRmB[i]
            maxS = -1 * 10 ** 10
        maxS = max(sRmB[i], maxS)
    ans = max(ans, maxS - minS)
    for i in range(N + 1):
        # print(smRB[i], minS)
        if smRB[i] <= minS:
            ans = max(ans, maxS - minS)
            minS = smRB[i]
            maxS = -1 * 10 ** 10
        maxS = max(smRB[i], maxS)
    ans = max(ans, maxS - minS)
    print(ans)





    return

if __name__ == '__main__':
    main()
0