結果
| 問題 | No.1433 Two color sequence | 
| コンテスト | |
| ユーザー |  学ぶマン | 
| 提出日時 | 2025-09-09 23:21:45 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 148 ms / 2,000 ms | 
| コード長 | 747 bytes | 
| コンパイル時間 | 368 ms | 
| コンパイル使用メモリ | 81,836 KB | 
| 実行使用メモリ | 130,232 KB | 
| 最終ジャッジ日時 | 2025-09-09 23:21:52 | 
| 合計ジャッジ時間 | 5,886 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
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))
            
            
            
        