結果
| 問題 |
No.2276 I Want AC
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-07 22:18:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 1,294 bytes |
| コンパイル時間 | 834 ms |
| コンパイル使用メモリ | 97,568 KB |
| 最終ジャッジ日時 | 2025-02-15 07:39:56 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 |
ソースコード
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
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;
const double PI=acos(-1);
int main(){
int N;
cin>>N;
string S;
cin>>S;
ll tmpcnt=0;
{
//すべての'?'を'C'にすると仮定
int cntA=0;
for(int i=0;i<N;i++){
if(S[i]=='A'){
cntA++;
}else{
//S[i]='C' or '?'
tmpcnt+=cntA;
}
}
}
ll ans=tmpcnt;
{
ll LA=0;
ll RC=0;
for(int i=1;i<N;i++){
if(S[i]=='C' || S[i]=='?')RC++;
}
for(int i=0;i<N;i++){
if(S[i]=='?'){
//'?'をAに変える.
tmpcnt-=LA;
tmpcnt+=RC;
ans=max(ans,tmpcnt);
}
if(S[i]!='C'){
//? or Aのとき
LA++;
}
if(i+1<N && S[i+1]!='A'){
//S[i+1]='C' or '?'のとき
RC--;
}
}
}
cout<<ans<<endl;
}