結果

問題 No.1933 ABC String
ユーザー ぷらぷら
提出日時 2022-04-14 15:04:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,245 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 199,720 KB
実行使用メモリ 12,496 KB
最終ジャッジ日時 2023-08-26 06:57:54
合計ジャッジ時間 6,555 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,496 KB
testcase_01 AC 5 ms
8,028 KB
testcase_02 AC 186 ms
8,064 KB
testcase_03 AC 12 ms
8,316 KB
testcase_04 AC 12 ms
8,056 KB
testcase_05 AC 8 ms
8,112 KB
testcase_06 AC 16 ms
8,032 KB
testcase_07 AC 12 ms
8,056 KB
testcase_08 AC 915 ms
8,076 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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;
    int ans = 0;
    for(int i = 0; i <= A+B; i++) {
        for(int j = 0; j <= A && j <= i; j++) {
            if(i-j > B) continue;
            for(int k = 0; k <= i; k++) {
                ans += COM(i,j)*COM(i+c-k-1,c-1)%mod*COM(A-j+b-1,b-1)%mod*COM(B-(i-j)+a-1,a-1)%mod*COM(C+a+b+k+(A+B-i),a+b+(A+B-i)+k)%mod;
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
}
0