提出 #28299055


ソースコード 拡げる

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

#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<

#define INF (ll)1e18
#define mod 998244353
#define maxn 1010

ll i, i1, j, k, k1, t, n, m, res, flag[10], a[maxn], b;
ll fc[maxn], nv[maxn], dp[maxn][maxn], x;

ll fxp(ll b, ll e) {
    ll r = 1, k = b;
    while (e != 0) {
        if (e % 2) r = (r * k) % mod;
        k = (k * k) % mod; e /= 2;
    }
    return r;
}

ll inv(ll x) {
    return fxp(x, mod - 2);
}

ll bnm(ll a, ll b) {
    ll i, r = 1;
    if (a < b || b < 0) return 0;
    for (i = a - b + 1; i <= a; i++) r = (r * i) % mod;
    r = (r * nv[b]) % mod;
    return r;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    #if !ONLINE_JUDGE && !EVAL
        ifstream cin("input.txt");
        ofstream cout("output.txt");
    #endif

    fc[0] = 1; nv[0] = 1;
    for (i = 1; i < maxn; i++) {
        fc[i] = (i * fc[i - 1]) % mod; nv[i] = inv(fc[i]);
    }

    cin >> n >> m;
    for (i = 1; i <= n; i++) {
        cin >> a[i];
    }

    dp[0][0] = 1;
    for (i = 1; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j >= 1) dp[i][j] = (dp[i][j] + a[i] * dp[i - 1][j - 1]) % mod;
        }
    }

    for (i = 0; i <= n; i++) {
        x = dp[n][n - i];
        x = (x * bnm(m, i)) % mod;
        x = (x * fc[i]) % mod;
        x = (x * fxp(n, m - i)) % mod;
        res = (res + x) % mod;
    }

    res = (res * inv(fxp(n, m))) % mod;
    cout << res << nl;

    return 0;
}

提出情報

提出日時
問題 G - Balls in Boxes
ユーザ TheScrasse
言語 C++ (GCC 9.2.1)
得点 600
コード長 1631 Byte
結果 AC
実行時間 22 ms
メモリ 11540 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 35
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 16 ms 11448 KiB
random_02.txt AC 14 ms 10000 KiB
random_03.txt AC 13 ms 11372 KiB
random_04.txt AC 5 ms 5348 KiB
random_05.txt AC 16 ms 11540 KiB
random_06.txt AC 8 ms 8256 KiB
random_07.txt AC 17 ms 11504 KiB
random_08.txt AC 8 ms 6680 KiB
random_09.txt AC 22 ms 11436 KiB
random_10.txt AC 12 ms 9396 KiB
random_11.txt AC 20 ms 11372 KiB
random_12.txt AC 12 ms 9212 KiB
random_13.txt AC 14 ms 11540 KiB
random_14.txt AC 11 ms 9884 KiB
random_15.txt AC 18 ms 11428 KiB
random_16.txt AC 12 ms 9560 KiB
random_17.txt AC 13 ms 11540 KiB
random_18.txt AC 10 ms 7008 KiB
random_19.txt AC 20 ms 11484 KiB
random_20.txt AC 2 ms 3644 KiB
random_21.txt AC 19 ms 11392 KiB
random_22.txt AC 2 ms 3528 KiB
random_23.txt AC 19 ms 11432 KiB
random_24.txt AC 3 ms 3528 KiB
random_25.txt AC 22 ms 11500 KiB
random_26.txt AC 2 ms 3524 KiB
random_27.txt AC 13 ms 11424 KiB
random_28.txt AC 2 ms 3588 KiB
random_29.txt AC 14 ms 11372 KiB
random_30.txt AC 2 ms 3632 KiB
random_31.txt AC 17 ms 11424 KiB
random_32.txt AC 2 ms 3556 KiB
sample_01.txt AC 2 ms 3588 KiB
sample_02.txt AC 2 ms 3592 KiB
sample_03.txt AC 2 ms 3676 KiB