結果

問題 No.1887 K Consecutive Ks (Easy)
ユーザー TatsuyaaaaTatsuyaaaa
提出日時 2022-03-25 23:35:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 201,876 KB
実行使用メモリ 38,528 KB
最終ジャッジ日時 2024-04-22 08:36:55
合計ジャッジ時間 18,660 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 OLE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 OLE -
testcase_14 OLE -
testcase_15 OLE -
testcase_16 OLE -
testcase_17 OLE -
testcase_18 OLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define ll long long

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<vector<mint>> dp(N+1, vector<mint>(N+1, 0));
    dp[0][0] = 1;
    for (int i=0;i<N;i++) {
        for (int j=0;j<=N;j++) {
            if (j == 0) {
                dp[i+1][1] += dp[i][j]*(M-1);
            } else {
                dp[i+1][1] += dp[i][j]*(M-2);
            }
            if (j+1 <= N && M-j > 0 && j > 0) dp[i+1][j+1] += dp[i][j]*(mint(M-j).inv())*(M-j-1);
        }
    }

    cout << "dp: " << "\n";
    for (int i=0;i<=N;i++) {
        for (int j=0;j<=N;j++) {
            cout << dp[i][j].val() << " ";
        }
        cout << "\n";
    }

    mint ans = mint(M).pow(N);
    // cout << ans.val() << "\n";
    for (int i=0;i<=N;i++) ans -= dp[N][i];
    cout << ans.val() << "\n";
    return 0;
}
0