結果

問題 No.1433 Two color sequence
ユーザー wolgnikwolgnik
提出日時 2021-03-19 22:04:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 618 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 119,512 KB
最終ジャッジ日時 2023-08-12 02:17:39
合計ジャッジ時間 4,874 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,300 KB
testcase_01 AC 67 ms
71,444 KB
testcase_02 AC 67 ms
71,376 KB
testcase_03 AC 136 ms
111,248 KB
testcase_04 AC 130 ms
111,236 KB
testcase_05 AC 68 ms
71,388 KB
testcase_06 AC 67 ms
71,388 KB
testcase_07 AC 66 ms
71,612 KB
testcase_08 AC 138 ms
119,512 KB
testcase_09 AC 144 ms
119,128 KB
testcase_10 AC 144 ms
117,772 KB
testcase_11 AC 143 ms
118,328 KB
testcase_12 AC 148 ms
118,716 KB
testcase_13 AC 146 ms
118,840 KB
testcase_14 AC 144 ms
118,916 KB
testcase_15 AC 142 ms
118,928 KB
testcase_16 AC 143 ms
119,064 KB
testcase_17 AC 143 ms
118,976 KB
testcase_18 AC 145 ms
119,224 KB
testcase_19 AC 144 ms
119,068 KB
testcase_20 AC 142 ms
119,180 KB
testcase_21 AC 144 ms
118,984 KB
testcase_22 AC 144 ms
119,232 KB
testcase_23 AC 144 ms
119,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
S = list(input())[: -1]
a = list(map(int, input().split()))

scores = [0] * N
for i in range(N):
  if S[i] == "R": scores[i] += a[i]
  else: scores[i] -= a[i]
  if i + 1 < N: scores[i + 1] += scores[i]

inf = 10 ** 15
scmx = [-inf] * N
scmn = [inf] * N
for i in range(N - 1, -1, -1):
  scmx[i] = scores[i]
  scmn[i] = scores[i]
  if i + 1 < N:
    scmx[i] = max(scmx[i], scmx[i + 1])
    scmn[i] = min(scmn[i], scmn[i + 1])

res = abs(scores[-1])
for i in range(N):
  res = max(res, abs(scmx[i] - scores[i]))
  res = max(res, abs(scmn[i] - scores[i]))

print(res)
0