結果

問題 No.2530 Yellow Cards
ユーザー 👑 chro_96chro_96
提出日時 2023-11-03 23:33:39
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,061 bytes
コンパイル時間 1,328 ms
コンパイル使用メモリ 30,136 KB
実行使用メモリ 197,316 KB
最終ジャッジ日時 2023-11-03 23:33:43
合計ジャッジ時間 4,132 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
197,316 KB
testcase_01 AC 71 ms
197,316 KB
testcase_02 AC 74 ms
197,316 KB
testcase_03 AC 71 ms
197,316 KB
testcase_04 AC 70 ms
197,316 KB
testcase_05 AC 54 ms
197,316 KB
testcase_06 AC 50 ms
197,316 KB
testcase_07 AC 181 ms
197,316 KB
testcase_08 AC 181 ms
197,316 KB
testcase_09 AC 201 ms
197,316 KB
testcase_10 AC 181 ms
197,316 KB
testcase_11 AC 180 ms
197,316 KB
testcase_12 AC 180 ms
197,316 KB
testcase_13 AC 180 ms
197,316 KB
testcase_14 AC 143 ms
197,316 KB
testcase_15 AC 107 ms
197,316 KB
testcase_16 AC 131 ms
197,316 KB
testcase_17 AC 152 ms
197,316 KB
testcase_18 AC 89 ms
197,316 KB
testcase_19 AC 59 ms
197,316 KB
testcase_20 AC 65 ms
197,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

long long power_mod (long long a, long long b, long long mod_num) {
  long long ans = 1LL;
  
  if (b > 0LL) {
    ans = power_mod(a, b/2LL, mod_num);
    ans = (ans * ans) % mod_num;
    if (b%2LL == 1LL) {
      ans = (ans * (a % mod_num)) % mod_num;
    }
  }
  
  return ans;
}

int main () {
  int n = 0;
  int k = 0;
  
  int res = 0;
  
  long long ans = 0LL;
  long long mod_num = 998244353LL;
  
  long long dp[5001][5001] = {};
  long long inv_n = 0LL;
  
  res = scanf("%d", &n);
  res = scanf("%d", &k);
  
  ans = (long long)n;
  inv_n = power_mod((long long)n, mod_num-2LL, mod_num);
  
  dp[0][0] = 1LL;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j <= n; j++) {
      long long tmp = (dp[i][j]*inv_n)%mod_num;
      if (j > 0) {
        ans += tmp*((long long)j);
        dp[i+1][j-1] += tmp*((long long)j);
        dp[i+1][j-1] %= mod_num;
      }
      if (j < n) {
        dp[i+1][j+1] += tmp*((long long)(n-j));
        dp[i+1][j+1] %= mod_num;
      }
    }
  }
  
  printf("%lld\n", ans%mod_num);
  return 0;
}
0