結果
問題 |
No.2276 I Want AC
|
ユーザー |
|
提出日時 | 2023-07-13 11:25:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,139 bytes |
コンパイル時間 | 993 ms |
コンパイル使用メモリ | 104,044 KB |
最終ジャッジ日時 | 2025-02-15 10:09:10 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 WA * 41 |
ソースコード
/* AAAA...AACCC...CCCが最適 */ #include<iostream> #include<set> #include<algorithm> #include<vector> #include<string> #include<set> #include<map> #include<numeric> #include<queue> #include<cmath> #include <unordered_set> using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair<int,int> P; typedef pair<int,P> PP; const ll MOD=998244353; int main(){ int N; cin>>N; string S; cin>>S; ll tot=0; int cntA=0; int cntC=0; //すべての?をCとしたとき for(int i=0;i<N;i++){ if(S[i]=='?' || S[i]=='C'){ cntC++; //Cにする tot+=cntA; }else if(S[i]=='A'){ cntA++;//[0,i]で出現したAの数 } } ll ans=tot; cntA=0; int cntA2=0; for(int i=0;i<N;i++){ if(S[i]=='C' || S[i]=='?'){ tot-=cntA*cntC; if(S[i]=='?'){ cntA++; cntC--; } tot+=cntA*cntC; } if(S[i]=='A'){ cntA++; } ans=max(tot,ans); } cout<<ans<<endl; }