結果

問題 No.1927 AB-CD
ユーザー ksukegames
提出日時 2023-03-25 13:33:46
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 5,798 ms
コンパイル使用メモリ 318,212 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-18 20:28:13
合計ジャッジ時間 7,538 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)
#define coutf(f) cout << fixed << setprecision(f)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

using mint = modint998244353;
const int mod = 998244353;

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};

int main() {
	int n;
	string s;
	cin >> n >> s;
	map<char, int> mp;
	rep(i, n) mp[s[i]]++;
	combination c(n);
	mint ans = c(n, mp['A'] + mp['B']);
	cout << ans.val() << endl;
	return 0;
}
0