提出 #75859985


ソースコード 拡げる

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

#define ll long long
#define pb push_back
#define endl '\n'

class Solution {

public:

    static const ll MOD = 998244353;

    vector<ll> fact, invFact;

    inline ll mul(ll a, ll b) {
        return (a * b) % MOD;
    }

    ll power(ll a, ll b) {

        ll ans = 1;

        while (b) {

            if (b & 1) {
                ans = mul(ans, a);
            }

            a = mul(a, a);

            b >>= 1;
        }

        return ans;
    }

    void build(ll n) {

        fact.resize(n + 1);
        invFact.resize(n + 1);

        fact[0] = 1;

        for (ll i = 1; i <= n; i++) {
            fact[i] = mul(fact[i - 1], i);
        }

        invFact[n] = power(fact[n], MOD - 2);

        for (ll i = n - 1; i >= 0; i--) {
            invFact[i] = mul(invFact[i + 1], i + 1);
        }
    }

    inline ll nCr(ll n, ll r) {

        if (r < 0 || r > n) {
            return 0;
        }

        return mul(fact[n], mul(invFact[r], invFact[n - r]));
    }

    ll solve(ll x1, ll x2, ll x3) {

        // 2 ke around gaps
        ll gaps = x2 + 1;

        ll ans = 0;

        for (ll k = 1; k <= min(x1, gaps); k++) {

            // k gaps choose for 1
            ll a = nCr(gaps, k);

            // 1s distribute
            ll b = nCr(x1 - 1, k - 1);

            ll rem = gaps - k;

            // baaki gaps me 3
            ll c = nCr(x3 + rem - 1, rem - 1);

            ll total = mul(a, mul(b, c));

            ans += total;
            ans %= MOD;
        }

        return ans;
    }
};

int main() {

    ll x1, x2, x3;
    cin >> x1 >> x2 >> x3;

    Solution obj;

    obj.build(x1 + x2 + x3 + 5);

    cout << obj.solve(x1, x2, x3) << endl;

    return 0;
}

提出情報

提出日時
問題 E - Count 123
ユーザ Naman____17
言語 C++23 (GCC 15.2.0)
得点 450
コード長 1853 Byte
結果 AC
実行時間 46 ms
メモリ 50316 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 3
AC × 33
セット名 テストケース
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt
ケース名 結果 実行時間 メモリ
00-sample-01.txt AC 1 ms 3596 KiB
00-sample-02.txt AC 1 ms 3436 KiB
00-sample-03.txt AC 46 ms 50088 KiB
01-01.txt AC 17 ms 22968 KiB
01-02.txt AC 9 ms 12968 KiB
01-03.txt AC 17 ms 21972 KiB
01-04.txt AC 11 ms 14976 KiB
01-05.txt AC 29 ms 32724 KiB
01-06.txt AC 18 ms 22108 KiB
01-07.txt AC 1 ms 3368 KiB
01-08.txt AC 45 ms 50156 KiB
01-09.txt AC 44 ms 50316 KiB
01-10.txt AC 44 ms 50012 KiB
01-11.txt AC 24 ms 34644 KiB
01-12.txt AC 24 ms 34472 KiB
01-13.txt AC 17 ms 25344 KiB
01-14.txt AC 16 ms 23772 KiB
01-15.txt AC 19 ms 23600 KiB
01-16.txt AC 8 ms 11832 KiB
01-17.txt AC 7 ms 11988 KiB
01-18.txt AC 12 ms 17848 KiB
01-19.txt AC 29 ms 34504 KiB
01-20.txt AC 25 ms 30896 KiB
01-21.txt AC 29 ms 34472 KiB
01-22.txt AC 11 ms 15232 KiB
01-23.txt AC 29 ms 34516 KiB
01-24.txt AC 20 ms 25036 KiB
01-25.txt AC 28 ms 34604 KiB
01-26.txt AC 22 ms 27824 KiB
01-27.txt AC 28 ms 34396 KiB
01-28.txt AC 10 ms 14128 KiB
01-29.txt AC 28 ms 34396 KiB
01-30.txt AC 20 ms 25772 KiB