結果
| 問題 |
No.2276 I Want AC
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-13 11:26:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,147 bytes |
| コンパイル時間 | 776 ms |
| コンパイル使用メモリ | 105,004 KB |
| 最終ジャッジ日時 | 2025-02-15 10:09:16 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 39 |
ソースコード
/*
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-=1LL*cntA*cntC;
if(S[i]=='?'){
cntA++;
cntC--;
}
tot+=1LL*cntA*cntC;
}
if(S[i]=='A'){
cntA++;
}
ans=max(tot,ans);
}
cout<<ans<<endl;
}