結果

問題 No.2381 Gift Exchange Party
ユーザー YTOKYTOK
提出日時 2023-07-14 23:17:35
言語 Julia
(1.10.2)
結果
WA  
実行時間 -
コード長 692 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 6,692 KB
実行使用メモリ 477,960 KB
最終ジャッジ日時 2024-04-09 14:17:40
合計ジャッジ時間 5,770 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 447 ms
257,240 KB
testcase_01 AC 443 ms
254,080 KB
testcase_02 WA -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 WA -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 625 ms
256,392 KB
testcase_21 TLE -
testcase_22 AC 620 ms
257,652 KB
testcase_23 AC 627 ms
254,924 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

toI(s=readline()) = parse(Int,s)
toVI(s=readline()) = toI.(split(s))

const MOD = 998244353
⊕(x,y) = mod(x+y,MOD)
⊖(x,y) = mod(x-y,MOD)
⊗(x,y) = mod(x*y,MOD)
⊘(x,y) = x⊗invmod(y,MOD)
↑(x,y) = powermod(x,y,MOD)

function main()
	n,p = toVI()
	solve(n,p) |> println
end

function solve(n,p)
	d,r = divrem(n,p)
	cnt = factmod(n)
	for d in 0:n÷p
		r = n - d*p
		cnt = cnt ⊖ combmod(n,r)⊗factmod(d*p)⊘factmod(p)↑d⊘factmod(d)⊗(factmod(p)-1)↑d
	end
	cnt
end

@generated function factmod(n)
	xs = zeros(Int,200001)
	xs[1] = 1
	for i in 1:200000
		xs[i+1] = xs[i]⊗i
	end
	return :($xs[n+1])
end

function combmod(n,r)
	factmod(n)⊘(factmod(r)⊗factmod(n-r))
end

main()
0