結果

問題 No.1433 Two color sequence
コンテスト
ユーザー koheijkt
提出日時 2025-09-09 23:21:45
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 134 ms / 2,000 ms
+ 817µs
コード長 747 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 523 ms
コンパイル使用メモリ 95,852 KB
実行使用メモリ 145,408 KB
最終ジャッジ日時 2026-07-14 23:30:47
合計ジャッジ時間 6,626 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 10**18
MOD = 998244353
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, groupby, accumulate
from heapq import heapify, heappop, heappush

N = int(input())
S = input()
A = list(map(int, input().split()))

rui = [0]
for i in range(N):
    if S[i] == 'R':
        rui.append(rui[-1] + A[i])
    else:
        rui.append(rui[-1] - A[i])

m, M = 0, 0
ansl = []
for i in range(1, N + 1):

    candi1 = abs(rui[i] - m)
    candi2 = abs(rui[i] - M)
    ansl.append(max(candi1, candi2))

    # 値更新
    m = min(m, rui[i])
    M = max(M, rui[i])

print(max(ansl))
0