結果
問題 |
No.1433 Two color sequence
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:03:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 116 ms / 2,000 ms |
コード長 | 709 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 81,896 KB |
実行使用メモリ | 119,400 KB |
最終ジャッジ日時 | 2025-03-20 21:03:31 |
合計ジャッジ時間 | 3,989 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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)