結果
| 問題 | No.2276 I Want AC | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-04-21 22:18:28 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 9 ms / 2,000 ms | 
| コード長 | 481 bytes | 
| コンパイル時間 | 1,991 ms | 
| コンパイル使用メモリ | 193,816 KB | 
| 最終ジャッジ日時 | 2025-02-12 11:54:39 | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 56 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  ll nw=0;
  int ca=0;
  rep(i,n){
    if(s.at(i)=='A') ca++;
    else nw+=ca;
  }
  int cc=n-ca;
  ll ans=nw;
  ca=0;
  rep(i,n){
    if(s.at(i)=='A') ca++;
    if(s.at(i)=='C') cc--;
    if(s.at(i)=='?'){
      cc--;
      nw-=ca;
      nw+=cc;
      ans=max(ans,nw);
      ca++;
    }
  }
  cout<<ans<<endl;
}
            
            
            
        