結果

問題 No.2530 Yellow Cards
ユーザー tomeruntomerun
提出日時 2023-11-03 22:05:08
言語 Crystal
(1.11.2)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 8,884 ms
コンパイル使用メモリ 291,032 KB
実行使用メモリ 206,592 KB
最終ジャッジ日時 2023-11-03 22:05:29
合計ジャッジ時間 12,892 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 303 ms
206,592 KB
testcase_08 AC 303 ms
206,592 KB
testcase_09 AC 322 ms
206,592 KB
testcase_10 AC 307 ms
206,588 KB
testcase_11 AC 300 ms
206,588 KB
testcase_12 AC 342 ms
206,592 KB
testcase_13 AC 303 ms
206,588 KB
testcase_14 AC 218 ms
160,984 KB
testcase_15 AC 141 ms
93,668 KB
testcase_16 AC 147 ms
104,128 KB
testcase_17 AC 234 ms
158,128 KB
testcase_18 AC 96 ms
66,292 KB
testcase_19 AC 28 ms
18,584 KB
testcase_20 AC 41 ms
32,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353i64

def inv(v)
  pow(v, MOD - 2)
end

def pow(v, p)
  ret = 1i64
  while p > 0
    if (p & 1i64) != 0
      ret *= v
      ret %= MOD
    end
    v *= v
    v %= MOD
    p >>= 1
  end
  ret
end

n, k = read_line.split.map(&.to_i)
dp = Array.new(k + 1) { Array.new(n + 1, 0i64) }
dp[0][0] = 1
1.upto(k) do |i|
  0.upto(n) do |j|
    if j < n
      dp[i][j + 1] += dp[i - 1][j] * (n - j)
      dp[i][j + 1] %= MOD
    end
    if j > 0
      dp[i][j - 1] += dp[i - 1][j] * j
      dp[i][j - 1] %= MOD
    end
  end
end
ans = 0i64
0.upto({n, k}.min) do |i|
  c = (k - i) // 2
  ans += dp[-1][i] * (n + c)
  ans %= MOD
end
puts ans * inv(pow(n.to_i64, k)) % MOD
0