結果

問題 No.1433 Two color sequence
ユーザー wolgnikwolgnik
提出日時 2021-03-19 22:04:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 618 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 117,244 KB
最終ジャッジ日時 2024-04-29 16:58:07
合計ジャッジ時間 3,603 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
52,096 KB
testcase_01 AC 32 ms
51,584 KB
testcase_02 AC 35 ms
51,584 KB
testcase_03 AC 103 ms
109,928 KB
testcase_04 AC 98 ms
110,456 KB
testcase_05 AC 36 ms
52,352 KB
testcase_06 AC 33 ms
51,840 KB
testcase_07 AC 34 ms
51,840 KB
testcase_08 AC 103 ms
117,244 KB
testcase_09 AC 111 ms
116,772 KB
testcase_10 AC 111 ms
115,908 KB
testcase_11 AC 109 ms
115,724 KB
testcase_12 AC 112 ms
116,504 KB
testcase_13 AC 113 ms
117,036 KB
testcase_14 AC 110 ms
116,912 KB
testcase_15 AC 109 ms
116,668 KB
testcase_16 AC 113 ms
117,060 KB
testcase_17 AC 114 ms
116,640 KB
testcase_18 AC 111 ms
116,540 KB
testcase_19 AC 109 ms
116,416 KB
testcase_20 AC 108 ms
116,420 KB
testcase_21 AC 108 ms
116,772 KB
testcase_22 AC 109 ms
116,416 KB
testcase_23 AC 111 ms
116,508 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