結果

問題 No.2530 Yellow Cards
ユーザー SSRSSSRS
提出日時 2023-11-03 22:00:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 493 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 207,384 KB
実行使用メモリ 394,296 KB
最終ジャッジ日時 2023-11-03 22:00:27
合計ジャッジ時間 7,758 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 170 ms
198,936 KB
testcase_03 AC 30 ms
35,520 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 168 ms
198,936 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 493 ms
394,244 KB
testcase_08 AC 407 ms
394,296 KB
testcase_09 AC 396 ms
394,296 KB
testcase_10 AC 416 ms
394,032 KB
testcase_11 AC 392 ms
393,504 KB
testcase_12 AC 393 ms
394,032 KB
testcase_13 AC 424 ms
393,240 KB
testcase_14 AC 328 ms
324,600 KB
testcase_15 AC 245 ms
239,064 KB
testcase_16 AC 194 ms
189,696 KB
testcase_17 AC 360 ms
331,200 KB
testcase_18 AC 91 ms
97,296 KB
testcase_19 AC 20 ms
23,376 KB
testcase_20 AC 124 ms
121,320 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>(N + K + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < K; i++){
    for (int j = 0; j < N + 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 <= N + K; i++){
    ans += dp[K][i] * (N + i) % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}
0