結果

問題 No.2530 Yellow Cards
ユーザー AngrySadEightAngrySadEight
提出日時 2023-10-24 00:06:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 719 ms / 2,000 ms
コード長 1,407 bytes
コンパイル時間 962 ms
コンパイル使用メモリ 76,912 KB
実行使用メモリ 198,992 KB
最終ジャッジ日時 2023-10-24 00:06:45
合計ジャッジ時間 9,088 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 692 ms
198,992 KB
testcase_08 AC 711 ms
198,992 KB
testcase_09 AC 685 ms
198,992 KB
testcase_10 AC 711 ms
198,728 KB
testcase_11 AC 684 ms
198,464 KB
testcase_12 AC 719 ms
198,728 KB
testcase_13 AC 684 ms
198,464 KB
testcase_14 AC 480 ms
140,120 KB
testcase_15 AC 307 ms
90,488 KB
testcase_16 AC 315 ms
92,600 KB
testcase_17 AC 524 ms
152,528 KB
testcase_18 AC 204 ms
61,184 KB
testcase_19 AC 50 ms
17,096 KB
testcase_20 AC 73 ms
23,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll my_pow(ll x, ll n, ll mod) {
    ll ret;
    if (n == 0) {
        ret = 1;
    } else if (n % 2 == 1) {
        ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod;
    } else {
        ret = my_pow((x * x) % mod, n / 2, mod);
    }
    return ret;
}

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

ll mod = 998244353;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<vector<ll>> dp(
        K + 1,
        vector<ll>(N + 1));  // i 番目のイベントまで終わって,イエローカードが j
                             // 回出されている確率
    dp[0][0] = 1;
    for (ll i = 0; i < K; i++) {
        for (ll j = 0; j <= N; j++) {
            if (j > 0) {
                dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j] * j) % mod;
            }
            if (j < N) {
                dp[i + 1][j + 1] =
                    (dp[i + 1][j + 1] + dp[i][j] * (N - j)) % mod;
            }
        }
    }
    ll div = my_pow(N, K, mod);
    ll ans = 0;
    for (ll i = 0; i <= N; i++) {
        // K 回イエローカードが出されていて現在 i
        // 人にイエローカードが出ているならば,退場したのは (K - i) / 2 人
        ans = (ans + ((K - i) / 2 + N) * dp[K][i]) % mod;
    }
    ans = (ans * inv(div, mod)) % mod;
    cout << ans << endl;
}
0