結果
問題 |
No.2381 Gift Exchange Party
|
ユーザー |
![]() |
提出日時 | 2023-07-17 22:25:45 |
言語 | Julia (2.11.2) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,893 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 962,528 KB |
最終ジャッジ日時 | 2024-10-01 17:28:46 |
合計ジャッジ時間 | 7,120 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 TLE * 1 |
other | MLE * 1 -- * 21 |
ソースコード
parseInt() = parse.(Int64, readline()::String |> split)::Vector{Int64} parseInt2() = parse.(Int64, readline()::String |> collect)::Vector{Int64} parseInt3() = parse(Int64, readline()::String)::Int64 module Modulo mod = 998244353 export Mint, pow mutable struct Mint m::Int64 Mint(x) = x ≥ 0 ? new(x % mod) : new((mod - (-x) % mod) % mod) end function Base.:+(x::Mint, y::Mint) return Mint(+(x.m, y.m)) end function Base.:-(x::Mint, y::Mint) return Mint(-(x.m, y.m)) end function Base.:*(x::Mint, y::Mint) return Mint(*(x.m, y.m)) end function inverse(x::Mint) a = x.m b = mod u = 1 v = 0 while b > 0 t = a ÷ b a -= t * b a, b = b, a u -= t * v u, v = v, u end return Mint(u) end function Base.:/(x::Mint, y::Mint) return x * inverse(y) end function pow(x::Mint, n::Int64) ret = Mint(1) while n > 0 if n & 1 != 0 ret *= x end x *= x n >>= 1 end return ret end end using .Modulo n, p = parseInt() memo = fill(false, n + 1, n + 1) dp = fill(Mint(0), n + 1, n + 1) function f(i::Int64, j::Int64) # iを分割する(大きさj以下のグループに分ける) if memo[i+1, j+1] return dp[i+1, j+1] end if i == 0 dp[i+1, j+1] = Mint(1) memo[i+1, j+1] = true return Mint(1) end if i == 1 dp[i+1, j+1] = Mint(0) memo[i+1, j+1] = true return Mint(0) end ret = Mint(0) for k = 2:j if k == p continue end for l = 1:i÷k ret += pow(Mint(1) / Mint(k), l) * f(i - k * l, k - 1) end end dp[i+1, j+1] = ret memo[i+1, j+1] = true return ret end function main() factn = Mint(1) for i = 2:n factn *= Mint(i) end (factn * f(n, n)).m |> println end main()