結果

問題 No.1927 AB-CD
ユーザー bit_kyoprobit_kyopro
提出日時 2022-05-06 23:00:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 2,137 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 199,512 KB
実行使用メモリ 27,364 KB
最終ジャッジ日時 2023-09-20 05:06:01
合計ジャッジ時間 5,757 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
26,744 KB
testcase_01 AC 45 ms
26,760 KB
testcase_02 AC 40 ms
26,700 KB
testcase_03 AC 41 ms
26,704 KB
testcase_04 AC 43 ms
27,172 KB
testcase_05 AC 45 ms
26,832 KB
testcase_06 AC 46 ms
26,936 KB
testcase_07 AC 45 ms
26,952 KB
testcase_08 AC 44 ms
26,804 KB
testcase_09 AC 48 ms
26,944 KB
testcase_10 AC 46 ms
27,100 KB
testcase_11 AC 47 ms
26,936 KB
testcase_12 AC 46 ms
26,900 KB
testcase_13 AC 41 ms
26,888 KB
testcase_14 AC 44 ms
26,892 KB
testcase_15 AC 42 ms
26,896 KB
testcase_16 AC 50 ms
26,952 KB
testcase_17 AC 46 ms
26,828 KB
testcase_18 AC 46 ms
26,964 KB
testcase_19 AC 48 ms
26,932 KB
testcase_20 AC 50 ms
27,024 KB
testcase_21 AC 46 ms
26,936 KB
testcase_22 AC 43 ms
26,808 KB
testcase_23 AC 52 ms
27,072 KB
testcase_24 AC 47 ms
27,364 KB
testcase_25 AC 48 ms
27,096 KB
testcase_26 AC 53 ms
27,040 KB
testcase_27 AC 45 ms
26,696 KB
testcase_28 AC 48 ms
26,836 KB
testcase_29 AC 43 ms
26,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
/*
#include<atcoder/all>
using namespace atcoder;
//using mint = modint1000000007;
using mint = modint998244353;
*/
//g++ -I/opt/ac-library ./**.cpp
using namespace std;
using ll = long long;
using ull = unsigned long long;
//const long long MOD = 1000000007;
const long long MOD = 998244353;
const long double PI = 3.14159265358979;
const long long INF = 1LL<<60;
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
#define deb(var) do{cout << #var << " : "; view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
void view(vector<string>& v){cout << endl;for(auto& s :v){view(s);}cout << endl;}
template<typename T> void view(vector<T>& v){for(auto& e :v){cout << e << " ";}cout << endl;}
template<typename T> void view(vector<vector<T>>& vv){cout << endl;for(auto& v:vv){view(v);}}
ll gcd(ll a, ll b){if (b == 0) return a;else return gcd(b, a % b);}
ll lcm(ll x,ll y){return ll(x/gcd(x,y))*y;}
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long

//MODの値を適切に定めておくこと
//MAXの値は問題によって変更すること
//main内でCOMinit()をすること
const int MAX = 1000000;
long long 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;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int32_t main() {
    COMinit();
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ab = 0;
    for (auto x : s) {
        if (x == 'A' or x == 'B') ab++;
    }
    cout << COM(n, ab) << endl;
}
0