結果

問題 No.1887 K Consecutive Ks (Easy)
ユーザー Tatsuyaaaa
提出日時 2022-03-25 23:35:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 201,592 KB
最終ジャッジ日時 2025-01-28 12:40:44
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2 OLE * 1
other WA * 10 OLE * 6
権限があれば一括ダウンロードができます

ソースコード

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