結果

問題 No.1433 Two color sequence
コンテスト
ユーザー lam6er
提出日時 2025-03-20 21:03:18
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 94 ms / 2,000 ms
+ 174µs
コード長 709 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 94 ms
コンパイル使用メモリ 64,632 KB
実行使用メモリ 91,092 KB
最終ジャッジ日時 2026-10-29 02:34:07
合計ジャッジ時間 4,417 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

if not c:
    print(0)
else:
    current_max = current_min = c[0]
    max_sub = current_max
    min_sub = current_min
    
    for num in c[1:]:
        prev_max, prev_min = current_max, current_min
        current_max = max(num, prev_max + num, prev_min + num)
        current_min = min(num, prev_max + num, prev_min + num)
        
        if current_max > max_sub:
            max_sub = current_max
        if current_min < min_sub:
            min_sub = current_min
    
    res = max(abs(max_sub), abs(min_sub))
    print(res)
0