結果

問題 No.1433 Two color sequence
ユーザー convexineqconvexineq
提出日時 2021-03-19 21:55:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 370 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 108,572 KB
最終ジャッジ日時 2024-04-29 16:43:09
合計ジャッジ時間 3,557 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,840 KB
testcase_01 AC 41 ms
51,712 KB
testcase_02 AC 32 ms
51,712 KB
testcase_03 AC 84 ms
108,572 KB
testcase_04 AC 85 ms
108,288 KB
testcase_05 AC 34 ms
51,584 KB
testcase_06 AC 34 ms
51,712 KB
testcase_07 AC 35 ms
51,584 KB
testcase_08 AC 101 ms
103,488 KB
testcase_09 AC 110 ms
103,644 KB
testcase_10 AC 108 ms
103,240 KB
testcase_11 AC 109 ms
103,516 KB
testcase_12 AC 117 ms
103,512 KB
testcase_13 AC 110 ms
103,400 KB
testcase_14 AC 113 ms
103,608 KB
testcase_15 AC 112 ms
103,888 KB
testcase_16 AC 112 ms
103,884 KB
testcase_17 AC 110 ms
103,384 KB
testcase_18 AC 106 ms
103,824 KB
testcase_19 AC 106 ms
103,816 KB
testcase_20 AC 109 ms
104,140 KB
testcase_21 AC 109 ms
103,748 KB
testcase_22 AC 107 ms
103,500 KB
testcase_23 AC 105 ms
103,368 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