結果

問題 No.1967 Sugoroku Optimization
ユーザー AngrySadEightAngrySadEight
提出日時 2022-06-03 21:46:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 1,655 ms
コンパイル使用メモリ 173,188 KB
実行使用メモリ 34,736 KB
最終ジャッジ日時 2023-10-21 01:46:44
合計ジャッジ時間 3,006 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,348 KB
testcase_01 AC 5 ms
4,348 KB
testcase_02 AC 6 ms
4,348 KB
testcase_03 AC 58 ms
34,736 KB
testcase_04 AC 6 ms
4,348 KB
testcase_05 AC 53 ms
31,304 KB
testcase_06 AC 56 ms
33,416 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 41 ms
24,440 KB
testcase_09 AC 32 ms
19,160 KB
testcase_10 AC 18 ms
10,712 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 38 ms
22,592 KB
testcase_13 AC 22 ms
12,824 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 5 ms
4,348 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 59 ms
34,736 KB
testcase_21 AC 6 ms
4,348 KB
testcase_22 AC 58 ms
34,736 KB
testcase_23 AC 38 ms
22,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(), v.end()
#define mod1 1000000007
#define mod2 998244353
typedef long long ll;

ll my_pow(ll x, ll n, ll mod){
    // 繰り返し二乗法.x^nを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;
}

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> inverse(5005);
    for (ll i = 1; i < 5005; i++){
        ll x = my_pow(i, mod2 - 2, mod2);
        inverse[i] = x;
    }

    vector<vector<ll>> dp(K + 1, vector<ll>(N + 1, 0));
    dp[0][0] = 1;
    for (ll i = 0; i < K; i++){
        for (ll j = 0; j < N; j++){
           dp[i + 1][j + 1] = (dp[i + 1][j + 1] + ((dp[i][j] * inverse[N - j]) % mod2)) % mod2;
        }
        for (ll j = 0; j < N; j++){
            dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i + 1][j]) % mod2;
        }
    }
    /*for (ll i = 0; i <= K; i++){
        for (ll j = 0; j <= N; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/
    ll ans = 0;
    for (ll i = 0; i <= K; i++){
        ans = (ans + dp[i][N] + mod2) % mod2;
    }
    cout << ans << endl;
}
0