結果

問題 No.1927 AB-CD
ユーザー SSRSSSRS
提出日時 2022-05-06 21:22:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,082 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 170,444 KB
実行使用メモリ 11,924 KB
最終ジャッジ日時 2023-09-20 02:06:28
合計ジャッジ時間 3,942 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 49 ms
6,988 KB
testcase_05 AC 46 ms
7,088 KB
testcase_06 AC 46 ms
6,844 KB
testcase_07 AC 41 ms
6,560 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 50 ms
7,304 KB
testcase_10 AC 39 ms
6,476 KB
testcase_11 AC 43 ms
6,740 KB
testcase_12 AC 21 ms
4,816 KB
testcase_13 AC 24 ms
5,144 KB
testcase_14 AC 4 ms
4,384 KB
testcase_15 AC 11 ms
4,384 KB
testcase_16 AC 44 ms
6,816 KB
testcase_17 AC 34 ms
6,400 KB
testcase_18 AC 36 ms
6,408 KB
testcase_19 AC 40 ms
6,432 KB
testcase_20 AC 53 ms
7,772 KB
testcase_21 AC 40 ms
6,560 KB
testcase_22 AC 18 ms
4,852 KB
testcase_23 AC 59 ms
11,268 KB
testcase_24 AC 64 ms
10,348 KB
testcase_25 AC 64 ms
10,840 KB
testcase_26 AC 65 ms
11,924 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
vector<long long> mf = {1};
vector<long long> mfi = {1};
long long modfact(int n){
	if (mf.size() > n){
		return mf[n];
	} else {
		for (int i = mf.size(); i <= n; i++){
			long long next = mf.back() * i % MOD;
			mf.push_back(next);
			mfi.push_back(modinv(next));
		}
		return mf[n];
	}
}
long long modfactinv(int n){
	if (mfi.size() > n){
		return mfi[n];
	} else {
		return modinv(modfact(n));
	}
}
long long modbinom(int n, int k){
	if (n < 0 || k < 0 || k > n){
		return 0;
	} else {
		return modfact(n) * modfactinv(k) % MOD * modfactinv(n - k) % MOD;
	}
}
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int AB = 0;
  for (int i = 0; i < N; i++){
    if (S[i] == 'A' || S[i] == 'B'){
      AB++;
    }
  }
  cout << modbinom(N, AB) << endl;
}
0