結果

問題 No.1933 ABC String
ユーザー ぷらぷら
提出日時 2022-04-15 16:26:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,893 bytes
コンパイル時間 4,699 ms
コンパイル使用メモリ 268,884 KB
実行使用メモリ 10,148 KB
最終ジャッジ日時 2023-08-26 06:58:43
合計ジャッジ時間 11,644 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,136 KB
testcase_01 AC 7 ms
8,096 KB
testcase_02 AC 6 ms
8,160 KB
testcase_03 AC 6 ms
8,148 KB
testcase_04 AC 6 ms
8,140 KB
testcase_05 AC 6 ms
8,220 KB
testcase_06 AC 6 ms
8,156 KB
testcase_07 AC 7 ms
8,128 KB
testcase_08 AC 6 ms
8,316 KB
testcase_09 AC 7 ms
8,196 KB
testcase_10 AC 7 ms
8,124 KB
testcase_11 AC 7 ms
8,192 KB
testcase_12 AC 7 ms
8,248 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 12 ms
8,640 KB
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

constexpr int mod = 998244353;

long long fac[200005], finv[200005], inv[200005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 200005; 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 1;
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

int main() {
    string S;
    int A,B,C;
    cin >> S >> A >> B >> C;
    int a = 0,b = 0,c = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'a') a++;
        if(S[i] == 'b') b++;
        if(S[i] == 'c') c++;
    }
    COMinit();
    A -= a;
    B -= b;
    C -= c;
    vector<int>tmp1(A+B+1);
    for(int i = 0; i <= A+B; i++) {
        tmp1[i] = COM(i+c-1,c-1)*COM(C+a+b+A+B-i,a+b+A+B-i)%mod;
        if(i) {
            tmp1[i] += tmp1[i-1];
            if(tmp1[i] >= mod) tmp1[i] -= mod;
        }
    }
    vector<long long>tmp2(B+1),tmp3(A+1);
    for(int i = 0; i <= B; i++) {
        tmp2[i] = modpow(fac[i],mod-2)*COM(B-i+a-1,a-1)%mod;
    }
    for(int i = 0; i <= A; i++) {
        tmp3[i] = modpow(fac[i],mod-2)*COM(A-i+b-1,b-1)%mod;
    }
    vector<long long>tmp4 = convolution(tmp2,tmp3);
    for(int i = 0; i <= A+B; i++) {
        tmp4[i] *= fac[i];
        tmp4[i] %= mod;
    }
    int ans = 0;
    for(int i = 0; i <= A+B; i++) {
        ans += 1ll*tmp1[i]*tmp4[i]%mod;
        if(ans >= mod) ans -= mod;
    }
    cout << ans << endl;
}
0