結果

問題 No.1927 AB-CD
ユーザー CleyLCleyL
提出日時 2023-06-20 01:51:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,016 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 76,416 KB
実行使用メモリ 10,668 KB
最終ジャッジ日時 2023-09-09 20:34:19
合計ジャッジ時間 2,878 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
10,172 KB
testcase_01 AC 11 ms
10,220 KB
testcase_02 AC 10 ms
10,132 KB
testcase_03 AC 10 ms
10,132 KB
testcase_04 AC 15 ms
10,632 KB
testcase_05 AC 15 ms
10,532 KB
testcase_06 AC 15 ms
10,308 KB
testcase_07 AC 15 ms
10,616 KB
testcase_08 AC 10 ms
10,200 KB
testcase_09 AC 17 ms
10,600 KB
testcase_10 AC 14 ms
10,424 KB
testcase_11 AC 15 ms
10,336 KB
testcase_12 AC 12 ms
10,336 KB
testcase_13 AC 13 ms
10,192 KB
testcase_14 AC 10 ms
10,116 KB
testcase_15 AC 12 ms
10,272 KB
testcase_16 AC 15 ms
10,496 KB
testcase_17 AC 14 ms
10,304 KB
testcase_18 AC 15 ms
10,240 KB
testcase_19 AC 14 ms
10,436 KB
testcase_20 AC 17 ms
10,668 KB
testcase_21 AC 14 ms
10,524 KB
testcase_22 AC 12 ms
10,392 KB
testcase_23 AC 16 ms
10,444 KB
testcase_24 AC 18 ms
10,356 KB
testcase_25 AC 18 ms
10,548 KB
testcase_26 AC 17 ms
10,400 KB
testcase_27 AC 10 ms
10,364 KB
testcase_28 AC 10 ms
10,328 KB
testcase_29 AC 11 ms
10,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

const long long MOD = 998244353;

template <int mod>
struct Combination {
  long long n_max;
  vector<long long> fac, inv, finv;
  Combination(int n):n_max(n), fac(n+1,1), inv(n+1,1), finv(n+1,1){
    for(int i = 2; n > i; 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;
    }
  }

  long long C(int n, int r){
    if(n < r)return 0;
    if(n > n_max)return 0;
    return (((fac[n]*finv[r])%mod)*finv[n-r])%mod;
  }

  long long P(int n, int r){
    if(n < r)return 0;
    if(n > n_max)return 0;
    return (fac[n]*finv[n-r])%mod;
  }

  long long H(int n, int r){
    if(n==0 && r==0)return 1;
    return C(n+r-1, r);
  }
};
using comb = Combination<MOD>;

int main(){
  int n;cin>>n;
  string s;cin>>s;
  vector<int> A(2);
  comb X(300010);

  for(int i = 0; n > i; i++){
    if(s[i] <= 'B'){
      A[0]++;
    }else{
      A[1]++;
    }
  }
  cout << X.C(n, A[0]) << endl;
}
0