結果

問題 No.1927 AB-CD
ユーザー da_ha_da_ha_
提出日時 2022-05-06 22:12:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 2,253 bytes
コンパイル時間 4,814 ms
コンパイル使用メモリ 260,256 KB
実行使用メモリ 15,764 KB
最終ジャッジ日時 2023-09-20 03:08:27
合計ジャッジ時間 7,175 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
15,372 KB
testcase_01 AC 15 ms
15,380 KB
testcase_02 AC 16 ms
15,328 KB
testcase_03 AC 15 ms
15,344 KB
testcase_04 AC 19 ms
15,504 KB
testcase_05 AC 19 ms
15,468 KB
testcase_06 AC 20 ms
15,452 KB
testcase_07 AC 19 ms
15,576 KB
testcase_08 AC 16 ms
15,432 KB
testcase_09 AC 20 ms
15,764 KB
testcase_10 AC 19 ms
15,532 KB
testcase_11 AC 18 ms
15,508 KB
testcase_12 AC 18 ms
15,508 KB
testcase_13 AC 18 ms
15,532 KB
testcase_14 AC 15 ms
15,376 KB
testcase_15 AC 16 ms
15,488 KB
testcase_16 AC 19 ms
15,504 KB
testcase_17 AC 18 ms
15,444 KB
testcase_18 AC 18 ms
15,556 KB
testcase_19 AC 18 ms
15,472 KB
testcase_20 AC 20 ms
15,540 KB
testcase_21 AC 18 ms
15,536 KB
testcase_22 AC 16 ms
15,456 KB
testcase_23 AC 20 ms
15,448 KB
testcase_24 AC 21 ms
15,532 KB
testcase_25 AC 20 ms
15,536 KB
testcase_26 AC 21 ms
15,528 KB
testcase_27 AC 16 ms
15,384 KB
testcase_28 AC 15 ms
15,408 KB
testcase_29 AC 14 ms
15,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef tuple<ll, ll, ll> Tll;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const double PI = 3.14159265358979323846;
int ddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int ddy[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

void cans(bool f) {
    if (f)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

template <typename T>
T gcd(T a, T b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

bool compare1(pair<ll, ll> a, pair<ll, ll> b) { return a.first < b.first; }
bool compare2(pair<ll, ll> a, pair<ll, ll> b) { return a.second < b.second; }

long long modpow(long long a, long long n, long long mod = 998244353) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

using mint = modint998244353;

const int MAX = 510000;
const int MOD = 998244353;

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;
}

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    ll no = 0;
    for (auto c : S) {
        if (c == 'A' || c == 'B') no++;
    }
    COMinit();
    cout << COM(N, no) << endl;
}
0