結果

問題 No.1433 Two color sequence
ユーザー 👑 H20H20
提出日時 2021-03-19 21:56:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 621 bytes
コンパイル時間 2,418 ms
コンパイル使用メモリ 86,648 KB
実行使用メモリ 108,988 KB
最終ジャッジ日時 2023-08-12 02:03:10
合計ジャッジ時間 5,795 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,232 KB
testcase_01 AC 70 ms
71,200 KB
testcase_02 AC 72 ms
71,408 KB
testcase_03 AC 135 ms
108,988 KB
testcase_04 AC 115 ms
108,108 KB
testcase_05 AC 73 ms
71,560 KB
testcase_06 AC 75 ms
71,340 KB
testcase_07 AC 74 ms
71,568 KB
testcase_08 AC 141 ms
107,720 KB
testcase_09 AC 145 ms
106,324 KB
testcase_10 AC 141 ms
103,860 KB
testcase_11 AC 138 ms
104,464 KB
testcase_12 AC 139 ms
106,720 KB
testcase_13 AC 140 ms
106,528 KB
testcase_14 AC 146 ms
106,508 KB
testcase_15 AC 147 ms
106,496 KB
testcase_16 AC 145 ms
105,832 KB
testcase_17 AC 144 ms
106,376 KB
testcase_18 AC 146 ms
106,264 KB
testcase_19 AC 146 ms
106,712 KB
testcase_20 AC 144 ms
105,808 KB
testcase_21 AC 151 ms
106,476 KB
testcase_22 AC 147 ms
106,520 KB
testcase_23 AC 142 ms
106,236 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