結果
問題 |
No.1433 Two color sequence
|
ユーザー |
![]() |
提出日時 | 2025-03-20 18:56:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 132 ms / 2,000 ms |
コード長 | 709 bytes |
コンパイル時間 | 170 ms |
コンパイル使用メモリ | 82,384 KB |
実行使用メモリ | 119,644 KB |
最終ジャッジ日時 | 2025-03-20 18:57:32 |
合計ジャッジ時間 | 4,680 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
n = int(input()) s = input().strip() a = list(map(int, input().split())) c = [] for i in range(n): if s[i] == 'R': c.append(a[i]) else: c.append(-a[i]) if not c: print(0) else: current_max = current_min = c[0] max_sub = current_max min_sub = current_min for num in c[1:]: prev_max, prev_min = current_max, current_min current_max = max(num, prev_max + num, prev_min + num) current_min = min(num, prev_max + num, prev_min + num) if current_max > max_sub: max_sub = current_max if current_min < min_sub: min_sub = current_min res = max(abs(max_sub), abs(min_sub)) print(res)