結果

問題 No.1433 Two color sequence
ユーザー convexineqconvexineq
提出日時 2021-03-19 21:55:54
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 370 bytes
コンパイル時間 546 ms
コンパイル使用メモリ 87,348 KB
実行使用メモリ 109,420 KB
最終ジャッジ日時 2023-08-12 02:01:06
合計ジャッジ時間 5,577 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,388 KB
testcase_01 AC 74 ms
71,308 KB
testcase_02 AC 71 ms
71,264 KB
testcase_03 AC 140 ms
109,268 KB
testcase_04 AC 136 ms
109,420 KB
testcase_05 AC 77 ms
71,452 KB
testcase_06 AC 73 ms
71,188 KB
testcase_07 AC 71 ms
71,180 KB
testcase_08 AC 135 ms
107,668 KB
testcase_09 AC 144 ms
106,540 KB
testcase_10 AC 148 ms
104,484 KB
testcase_11 AC 142 ms
104,600 KB
testcase_12 AC 144 ms
106,584 KB
testcase_13 AC 150 ms
106,672 KB
testcase_14 AC 150 ms
106,636 KB
testcase_15 AC 151 ms
106,380 KB
testcase_16 AC 148 ms
106,632 KB
testcase_17 AC 149 ms
106,392 KB
testcase_18 AC 149 ms
106,592 KB
testcase_19 AC 149 ms
106,544 KB
testcase_20 AC 148 ms
106,600 KB
testcase_21 AC 151 ms
106,536 KB
testcase_22 AC 148 ms
106,636 KB
testcase_23 AC 144 ms
106,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Kadane(a):
   v = -1<<60 # i を右端とする区間和のmax
   m = -1<<60 # max(v0,...,vi)
   for ai in a:
       v = max(v+ai,ai)
       m = max(m,v)
   return m

n = int(input())
s = input()
*a, = map(int,input().split())
for i in range(n):
    if s[i]=="B": a[i] = -a[i]
x = abs(Kadane(a))
for i in range(n):
    a[i] = -a[i]
y = abs(Kadane(a))
print(max(x,y))
0