結果

問題 No.2276 I Want AC
ユーザー nagisa5101nagisa5101
提出日時 2023-04-21 21:48:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,872 bytes
コンパイル時間 4,032 ms
コンパイル使用メモリ 257,848 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-24 07:56:57
合計ジャッジ時間 5,643 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 7 ms
8,064 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 4 ms
6,144 KB
testcase_16 AC 4 ms
5,760 KB
testcase_17 AC 6 ms
7,808 KB
testcase_18 AC 5 ms
6,784 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 6 ms
8,320 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 7 ms
8,448 KB
testcase_24 AC 7 ms
8,704 KB
testcase_25 AC 7 ms
8,576 KB
testcase_26 AC 6 ms
8,576 KB
testcase_27 AC 6 ms
8,576 KB
testcase_28 AC 6 ms
8,704 KB
testcase_29 AC 6 ms
8,576 KB
testcase_30 AC 6 ms
8,704 KB
testcase_31 AC 5 ms
8,576 KB
testcase_32 AC 7 ms
8,576 KB
testcase_33 AC 7 ms
8,448 KB
testcase_34 AC 6 ms
8,448 KB
testcase_35 AC 5 ms
8,448 KB
testcase_36 AC 5 ms
8,448 KB
testcase_37 AC 5 ms
8,448 KB
testcase_38 AC 5 ms
8,576 KB
testcase_39 AC 5 ms
8,448 KB
testcase_40 AC 5 ms
8,448 KB
testcase_41 AC 5 ms
8,448 KB
testcase_42 AC 6 ms
8,320 KB
testcase_43 AC 5 ms
8,448 KB
testcase_44 AC 5 ms
8,576 KB
testcase_45 AC 6 ms
8,576 KB
testcase_46 AC 7 ms
8,448 KB
testcase_47 AC 6 ms
8,448 KB
testcase_48 AC 6 ms
8,448 KB
testcase_49 AC 6 ms
8,448 KB
testcase_50 AC 6 ms
8,448 KB
testcase_51 AC 6 ms
8,576 KB
testcase_52 AC 7 ms
8,576 KB
testcase_53 AC 7 ms
8,448 KB
testcase_54 AC 6 ms
8,576 KB
testcase_55 AC 6 ms
8,448 KB
testcase_56 AC 5 ms
8,448 KB
testcase_57 AC 5 ms
8,448 KB
testcase_58 AC 5 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace atcoder;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, n, m) for (int i = n; i < (int)(m); i++)
#define repll2(i, n, m) for (long long i = n; i < (long long)(m); i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vvvl=vector<vvl>;
using vld=vector<ld>;
using vvld=vector<vld>;

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

const double PI = acos(-1);
//const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=(1LL<<60);
const int INF2=(1<<30);
//using mint=modint1000000007;
//using mint=modint998244353;

int n;
string s;
ll cnt_a[200010],cnt_c[200010],cnt_q[200010];



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin>>n;
    cin>>s;
    cnt_a[0]=0,cnt_c[0]=0,cnt_q[0]=0;
    rep(i,n){
        cnt_a[i+1]=cnt_a[i];
        cnt_c[i+1]=cnt_c[i];
        cnt_q[i+1]=cnt_q[i];
        if(s[i]=='A')cnt_a[i+1]++;
        else if(s[i]=='C')cnt_c[i+1]++;
        else cnt_q[i+1]++;
    }
    ll ans=-INF;
    ll ca=cnt_a[n],cc=cnt_c[n],cq=cnt_q[n];
    ll base=0;
    for(int i=1;i<n+1;i++){
        if(s[i-1]=='A')base+=cc-cnt_c[i]+cq-cnt_q[i];
        //else base+=cnt_a[i];
    }
    //cout<<base<<endl;
    ans=base;
    for(int i=1;i<n+1;i++){
        //i+1より左の?は全てA,右はC
        if(s[i-1]!='?')continue;
        base-=cnt_a[i]+cnt_q[i-1];
        base+=cc-cnt_c[i]+cq-cnt_q[i];
        ans=max(ans,base);
        //cout<<i<<" "<<base<<endl;
    }
    cout<<ans<<endl;
    return 0;
}
0