結果

問題 No.1933 ABC String
ユーザー ytqm3ytqm3
提出日時 2022-05-06 17:44:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,332 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 200,316 KB
実行使用メモリ 15,208 KB
最終ジャッジ日時 2023-09-19 06:50:51
合計ジャッジ時間 14,102 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
15,208 KB
testcase_01 AC 8 ms
8,244 KB
testcase_02 AC 9 ms
8,144 KB
testcase_03 AC 7 ms
8,156 KB
testcase_04 AC 7 ms
8,368 KB
testcase_05 AC 7 ms
8,084 KB
testcase_06 AC 7 ms
8,096 KB
testcase_07 AC 7 ms
8,048 KB
testcase_08 AC 16 ms
8,088 KB
testcase_09 AC 22 ms
8,088 KB
testcase_10 AC 21 ms
8,092 KB
testcase_11 AC 49 ms
8,124 KB
testcase_12 AC 18 ms
8,316 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 TLE -
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 P = 0,Q = 0,R = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'a') P++;
        if(S[i] == 'b') Q++;
        if(S[i] == 'c') R++;
    }
    COMinit();
    int T=A-P,U=B-Q,V=C-R;
    int ans = 0;
    for(int k = 0; k <= T+U; k++) {
        int cnt1 = 0;
        for(int i = 0; i <= k; i++) {
            cnt1 += COM(R-1+i,R-1)*COM(V+P+Q+T+U-i+1-1,V)%mod;
            cnt1 %= mod;
        }
        int cnt2 = 0;
        for(int i = max(0,k-U); i <= T && i <= k; i++) {
            cnt2 += COM(k,i)*COM(T-i+Q-1,Q-1)%mod*COM(U-(k-i)+P-1,P-1)%mod;
            cnt2 %= mod;
        }
        ans += (long(cnt1) * cnt2) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}
0