結果

問題 No.1927 AB-CD
ユーザー monnumonnu
提出日時 2022-05-06 23:30:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 3,953 ms
コンパイル使用メモリ 228,324 KB
実行使用メモリ 17,920 KB
最終ジャッジ日時 2023-09-20 06:41:26
合計ジャッジ時間 6,005 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
17,524 KB
testcase_01 AC 15 ms
17,788 KB
testcase_02 AC 16 ms
17,512 KB
testcase_03 AC 16 ms
17,552 KB
testcase_04 AC 20 ms
17,584 KB
testcase_05 AC 20 ms
17,584 KB
testcase_06 AC 20 ms
17,640 KB
testcase_07 AC 20 ms
17,736 KB
testcase_08 AC 17 ms
17,540 KB
testcase_09 AC 20 ms
17,604 KB
testcase_10 AC 20 ms
17,740 KB
testcase_11 AC 19 ms
17,608 KB
testcase_12 AC 18 ms
17,628 KB
testcase_13 AC 18 ms
17,588 KB
testcase_14 AC 16 ms
17,484 KB
testcase_15 AC 16 ms
17,600 KB
testcase_16 AC 20 ms
17,920 KB
testcase_17 AC 20 ms
17,636 KB
testcase_18 AC 19 ms
17,588 KB
testcase_19 AC 19 ms
17,796 KB
testcase_20 AC 21 ms
17,620 KB
testcase_21 AC 19 ms
17,608 KB
testcase_22 AC 16 ms
17,612 KB
testcase_23 AC 21 ms
17,576 KB
testcase_24 AC 21 ms
17,784 KB
testcase_25 AC 22 ms
17,596 KB
testcase_26 AC 22 ms
17,680 KB
testcase_27 AC 16 ms
17,456 KB
testcase_28 AC 16 ms
17,636 KB
testcase_29 AC 16 ms
17,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define INF 1000000000
#define MOD 998244353
#define MAX 600000

ll fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=(fac[i-1]*i)%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

ll COM(int n,int k){
  static bool flag=false;
  if(!flag){
    COMinit();
    flag=true;
  }

  if(n<k){
    return 0;
  }
  if(n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  int N;
  string S;
  cin>>N>>S;
  int cnt=0;
  for(int i=0;i<N;i++){
    if((S[i]=='A')||(S[i]=='B')){
      cnt++;
    }
  }
  ll ans=COM(N,cnt);
  cout<<ans<<endl;
}
0