結果

問題 No.1433 Two color sequence
ユーザー 👑 H20H20
提出日時 2021-03-19 21:56:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 621 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 104,048 KB
最終ジャッジ日時 2024-04-29 16:44:45
合計ジャッジ時間 3,807 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,224 KB
testcase_01 AC 39 ms
51,840 KB
testcase_02 AC 40 ms
51,712 KB
testcase_03 AC 95 ms
103,808 KB
testcase_04 AC 92 ms
102,144 KB
testcase_05 AC 40 ms
52,224 KB
testcase_06 AC 40 ms
51,968 KB
testcase_07 AC 39 ms
51,840 KB
testcase_08 AC 122 ms
103,860 KB
testcase_09 AC 126 ms
103,420 KB
testcase_10 AC 124 ms
102,152 KB
testcase_11 AC 122 ms
103,088 KB
testcase_12 AC 125 ms
103,568 KB
testcase_13 AC 125 ms
103,692 KB
testcase_14 AC 124 ms
103,652 KB
testcase_15 AC 126 ms
103,788 KB
testcase_16 AC 124 ms
103,268 KB
testcase_17 AC 124 ms
104,048 KB
testcase_18 AC 125 ms
103,400 KB
testcase_19 AC 125 ms
103,528 KB
testcase_20 AC 123 ms
103,148 KB
testcase_21 AC 123 ms
103,532 KB
testcase_22 AC 124 ms
103,544 KB
testcase_23 AC 124 ms
103,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def maxSum(arr):

  cur_max = glob_max = float('-inf')
  glob_start = glob_end = cur_start = -1

  for index, item in enumerate(arr):

    if item > cur_max + item:
      cur_max = item
      cur_start = index
    else:
      cur_max += item

    if cur_max > glob_max:
      glob_max = cur_max
      glob_start = cur_start
      glob_end = index
  return arr[glob_start:glob_end+1]

N = int(input())
S = input()
A = list(map(int, input().split())) 
R = [0]*N
B = [0]*N
for i in range(N):
    if S[i]=='R':
        A[i]=-A[i]
ans = sum(maxSum(A))
for i in range(N):
    A[i]=-A[i]
ans = max(ans,sum(maxSum(A)))
print(ans)
0