結果

問題 No.2530 Yellow Cards
ユーザー SSRSSSRS
提出日時 2023-11-03 22:42:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 2,520 ms
コンパイル使用メモリ 207,060 KB
実行使用メモリ 198,940 KB
最終ジャッジ日時 2023-11-03 22:42:46
合計ジャッジ時間 6,691 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 191 ms
198,940 KB
testcase_03 AC 32 ms
35,524 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 183 ms
198,940 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 230 ms
198,940 KB
testcase_08 AC 250 ms
198,940 KB
testcase_09 AC 237 ms
198,940 KB
testcase_10 AC 227 ms
198,676 KB
testcase_11 AC 234 ms
198,676 KB
testcase_12 AC 236 ms
198,940 KB
testcase_13 AC 237 ms
198,412 KB
testcase_14 AC 220 ms
188,116 KB
testcase_15 AC 171 ms
152,212 KB
testcase_16 AC 116 ms
100,732 KB
testcase_17 AC 232 ms
182,308 KB
testcase_18 AC 46 ms
39,748 KB
testcase_19 AC 9 ms
9,652 KB
testcase_20 AC 105 ms
101,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
  int N, K;
  cin >> N >> K;
  vector<long long> inv(N + 1);
  inv[1] = 1;
  for (int i = 2; i <= N; i++){
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
  }
  vector<vector<long long>> dp(K + 1, vector<long long>(K + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < K; i++){
    for (int j = 0; j < K; j++){
      if (dp[i][j] > 0){
        int c = i - j * 2;
        dp[i + 1][j] += dp[i][j] * (N - c) % MOD * inv[N] % MOD;
        dp[i + 1][j] %= MOD;
        dp[i + 1][j + 1] += dp[i][j] * c % MOD * inv[N] % MOD;
        dp[i + 1][j + 1] %= MOD;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i <= K; i++){
    ans += dp[K][i] * (N + i) % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}
0