結果

問題 No.1433 Two color sequence
ユーザー U S
提出日時 2021-03-20 03:58:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 82,896 KB
実行使用メモリ 105,232 KB
最終ジャッジ日時 2024-11-19 10:56:08
合計ジャッジ時間 4,849 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

# import sys
# input = sys.stdin.readline
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))
import math
import bisect
from copy import deepcopy as dc
from itertools import accumulate
from collections import Counter, defaultdict, deque
def ceil(U,V):return (U+V-1)//V
def modf1(N,MOD):return (N-1)%MOD+1
inf = int(1e30)
mod = 998244353

def subseg_max(lst):
    ans_mn,ans_mx = int(1e30),-int(1e30)
    mn,mx = 0,0
    for i in range(len(lst)):
        mn = min(mn+lst[i],0)
        mx = max(mx+lst[i],0)
        ans_mn = min(ans_mn,mn)
        ans_mx = max(ans_mx,mx)
    return ans_mx,ans_mn

n =int(input())
s = input()
a = lmp()
for i in range(n):
    if s[i] == "B":a[i]*=-1
a,b = subseg_max(a)
print(max(abs(a),abs(b)))







0