結果

問題 No.2276 I Want AC
ユーザー えいるえいる
提出日時 2023-04-21 21:51:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,407 bytes
コンパイル時間 4,225 ms
コンパイル使用メモリ 226,932 KB
実行使用メモリ 8,068 KB
最終ジャッジ日時 2024-04-24 08:00:29
合計ジャッジ時間 6,938 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 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 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 15 ms
6,080 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 10 ms
5,376 KB
testcase_16 AC 9 ms
5,376 KB
testcase_17 AC 17 ms
6,672 KB
testcase_18 AC 12 ms
5,596 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 20 ms
6,964 KB
testcase_21 AC 8 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 18 ms
6,960 KB
testcase_24 AC 17 ms
6,960 KB
testcase_25 AC 18 ms
6,708 KB
testcase_26 AC 19 ms
7,356 KB
testcase_27 AC 19 ms
6,896 KB
testcase_28 AC 17 ms
8,068 KB
testcase_29 AC 15 ms
7,572 KB
testcase_30 AC 18 ms
7,180 KB
testcase_31 AC 14 ms
7,336 KB
testcase_32 AC 19 ms
6,900 KB
testcase_33 AC 18 ms
7,188 KB
testcase_34 AC 21 ms
7,444 KB
testcase_35 AC 10 ms
5,376 KB
testcase_36 AC 12 ms
7,340 KB
testcase_37 AC 21 ms
7,340 KB
testcase_38 AC 10 ms
5,376 KB
testcase_39 AC 11 ms
5,376 KB
testcase_40 AC 12 ms
7,464 KB
testcase_41 AC 11 ms
7,468 KB
testcase_42 AC 21 ms
7,204 KB
testcase_43 AC 21 ms
7,468 KB
testcase_44 AC 14 ms
6,320 KB
testcase_45 AC 19 ms
6,928 KB
testcase_46 AC 17 ms
6,188 KB
testcase_47 AC 13 ms
6,316 KB
testcase_48 AC 13 ms
6,184 KB
testcase_49 AC 19 ms
6,960 KB
testcase_50 AC 19 ms
6,928 KB
testcase_51 AC 18 ms
6,184 KB
testcase_52 AC 18 ms
6,440 KB
testcase_53 AC 19 ms
6,988 KB
testcase_54 AC 14 ms
6,376 KB
testcase_55 AC 13 ms
6,316 KB
testcase_56 AC 12 ms
6,444 KB
testcase_57 AC 11 ms
5,376 KB
testcase_58 AC 13 ms
7,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vvvl=vector<vector<vector<long long>>>;
using pl=pair<long long,long long>;
using vpl=vector<pair<long long,long long>>;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#include <atcoder/all>
using namespace atcoder;

long long modpow(long long a, long long n, long long mo){long long res=1;while(n>0){if(n&1){res=res*a%mo;}a=a*a%mo;n>>=1;}return res;}
long long Pow(long long a, long long n){long long res=1;while(n>0){if(n&1){res=res*a;}a=a*a;n>>=1;}return res;}

const ll MOD=998244353;
const ll INF=(1ll<<60);

int main(){
  ll N;
  cin>>N;
  string S;
  cin>>S;
  fenwick_tree<ll> fw(N);
  vl memo;
  vl C;
  rep(i,N){
    if(S[i]!='C'){
      fw.add(i,1);
    }
    else C.pb(i);
    if(S[i]=='?') memo.pb(i);
  }
  ll ans=0;
  reverse(all(memo));
  rep(i,C.size()){
    ans+=fw.sum(0,C[i]);
  }
  ll an=ans;
  rep(i,memo.size()){
    an-=(N-memo[i])-fw.sum(memo[i],N);//Cの数
    fw.add(memo[i],-1);
    an+=fw.sum(0,memo[i]);//Aの数
    ans=max(an,ans);
  }
  cout<<ans<<endl;
}
0