結果

問題 No.2528 pop_(backfront or not)
ユーザー tomeruntomerun
提出日時 2023-11-03 21:47:13
言語 Crystal
(1.11.2)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 531 bytes
コンパイル時間 16,044 ms
コンパイル使用メモリ 280,592 KB
実行使用メモリ 68,856 KB
最終ジャッジ日時 2023-11-03 21:47:40
合計ジャッジ時間 13,382 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 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 3 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 5 ms
5,496 KB
testcase_09 AC 12 ms
9,784 KB
testcase_10 AC 36 ms
20,736 KB
testcase_11 AC 34 ms
25,228 KB
testcase_12 AC 44 ms
28,304 KB
testcase_13 AC 49 ms
36,112 KB
testcase_14 AC 58 ms
40,376 KB
testcase_15 AC 89 ms
62,568 KB
testcase_16 AC 106 ms
68,856 KB
testcase_17 AC 108 ms
68,856 KB
testcase_18 AC 109 ms
68,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353i64
n = read_line.to_i
dp = Array.new(n) { Array.new(2 * n + 1, 0i64) }
dp[0][1] = 1
1.upto(n - 1) do |i|
  len = 2 * i + 1
  1.upto(len) do |j|
    dp[i][j] += dp[i - 1][j - 1]
    dp[i][j] += dp[i - 1][j] * ((len - j).to_i64 * (len - j - 1) // 2 % MOD)
    dp[i][j] %= MOD
    dp[i][j] += dp[i - 1][j - 1] * ((len - j).to_i64 * (j - 1) % MOD)
    dp[i][j] %= MOD
    if j > 2
      dp[i][j] += dp[i - 1][j - 2] * ((j - 1).to_i64 * (j - 2) // 2 % MOD)
      dp[i][j] %= MOD
    end
  end
end
puts dp[-1].join("\n")
0