結果
問題 |
No.2276 I Want AC
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:40:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 571 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 82,308 KB |
実行使用メモリ | 67,864 KB |
最終ジャッジ日時 | 2025-03-20 20:40:54 |
合計ジャッジ時間 | 5,295 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
n = int(input()) s = input().strip() max_right_c = [0] * (n + 1) for i in range(n - 1, -1, -1): if s[i] == 'C' or s[i] == '?': max_right_c[i] = max_right_c[i + 1] + 1 else: max_right_c[i] = max_right_c[i + 1] a = 0 total = 0 for i in range(n): if s[i] == 'A': a += 1 elif s[i] == 'C': total += a else: # It's '?', decide between A or C current_max_right = max_right_c[i + 1] if i + 1 < n else 0 if a >= current_max_right: total += a else: a += 1 print(total)