結果
問題 |
No.2276 I Want AC
|
ユーザー |
![]() |
提出日時 | 2024-08-18 23:10:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 91 ms / 2,000 ms |
コード長 | 660 bytes |
コンパイル時間 | 375 ms |
コンパイル使用メモリ | 82,036 KB |
実行使用メモリ | 76,124 KB |
最終ジャッジ日時 | 2024-08-18 23:10:14 |
合計ジャッジ時間 | 5,687 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
N = int(input()) S = input() # ? が全て C のときの AC の個数 ac = 0 a = 0 for c in S: match c: case 'C' | '?': ac += a case 'A': a += 1 ans = ac rc = S.count('C') + S.count('?') # 右側にある C の個数 la = 0 d = 0 for c in S: match c: case '?': # C -> A に変えたときの差分 d -= la # 左側の A の個数分だけ減る d += (rc-1) # 右側の C の個数分だけ増える ans = max(ans, ac + d) la += 1 rc -= 1 case 'A': la += 1 case 'C': rc -= 1 print(ans)