結果
| 問題 |
No.2276 I Want AC
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-13 12:08:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 2,000 ms |
| コード長 | 1,356 bytes |
| コンパイル時間 | 842 ms |
| コンパイル使用メモリ | 105,920 KB |
| 最終ジャッジ日時 | 2025-02-15 10:09:32 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 |
ソースコード
/*
AC
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の数
}
}
cntA=0;
ll ans=tot;
/*
cntA=[0,i]にあるAの数
cntC=[i,N-1]にあるCの数
*/
for(int i=0;i<N;i++){
if(S[i]=='C'){
cntC--;
}
else if(S[i]=='A'){
cntA++;
}else if(S[i]=='?'){
/*
この時点で i番目はCになっているので
cntA=[0,i)のAの数
cntC=[i,N-1]のCの数
*/
tot-=1LL*cntA*cntC;
cntA++;
cntC--;
tot+=1LL*cntA*cntC;
ans=max(tot,ans);
}
}
cout<<ans<<endl;
}