結果

問題 No.1967 Sugoroku Optimization
ユーザー ぷらぷら
提出日時 2022-06-03 21:43:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 2,456 ms
コンパイル使用メモリ 203,508 KB
実行使用メモリ 19,304 KB
最終ジャッジ日時 2023-10-21 01:43:35
合計ジャッジ時間 3,120 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 16 ms
19,296 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 14 ms
18,664 KB
testcase_06 AC 15 ms
18,692 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 12 ms
16,616 KB
testcase_09 AC 9 ms
12,520 KB
testcase_10 AC 7 ms
10,472 KB
testcase_11 AC 3 ms
4,372 KB
testcase_12 AC 11 ms
14,568 KB
testcase_13 AC 7 ms
10,472 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 3 ms
4,372 KB
testcase_16 AC 4 ms
6,376 KB
testcase_17 AC 3 ms
6,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 16 ms
19,288 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 16 ms
19,304 KB
testcase_23 AC 11 ms
14,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int mod = 998244353;

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

int dp[2002][2002];

int main() {
    int N,K;
    cin >> N >> K;
    vector<int>tmp(N+1);
    for(int i = 1; i <= N; i++) {
        tmp[i] = modpow(i,mod-2);
    }
    dp[K][N] = 1;
    for(int i = K-1; i >= 0; i--) {
        dp[i][N] = 1;
        int sum = 1;
        for(int j = N-1; j >= 0; j--) {
            dp[i][j] = 1ll*sum*tmp[N-j]%mod;
            sum += dp[i+1][j];
            if(sum >= mod) sum -= mod;
        }
    }
    cout << dp[0][0] << endl;
}
0