結果

問題 No.2276 I Want AC
ユーザー FplusFplusF
提出日時 2023-04-22 20:13:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 908 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 193,644 KB
最終ジャッジ日時 2025-02-12 13:08:31
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i=0;i<(long long)(n);i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll la=0,rc=0;
    ll now=0;
    rep(i,n){
        if(s[i]=='A') la++;
        else{
            now+=la;
            rc++;
        }
    }
    la=0;
    ll ans=now;
    rep(i,n){
        if(s[i]=='A') la++;
        if(s[i]=='C') rc--;
        if(s[i]=='?'){
            rc--;
            now-=la;
            la++;
            now+=rc;
            chmax(ans,now);
        }
    }
    cout << ans << '\n';
}
0