結果
問題 |
No.3030 Kruskal-Katona
|
ユーザー |
![]() |
提出日時 | 2025-02-02 19:06:51 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 753 bytes |
コンパイル時間 | 2,648 ms |
コンパイル使用メモリ | 107,152 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-07 22:40:08 |
合計ジャッジ時間 | 2,798 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import std.algorithm, std.array, std.bigint, std.conv, std.stdio, std.typecons, std.range; BigInt[] solve(BigInt N, BigInt i) { if (N == 0) return []; // special case if (i == 1) return [N]; BigInt Ni = i; BigInt b = 1; while (1) { auto b2 = binom(Ni+1, i); if (b2 > N) break; else ++Ni, b = b2; } return [Ni] ~ solve(N - b, i-1); } void main() { auto tmp = readln.split.to!(ulong[]); auto seq = solve(BigInt(tmp[0]), BigInt(tmp[1])); auto ans = seq.map!(i => i.to!string ~ " ").reduce!`a ~ b`[0 .. $-1]; writeln(ans); } BigInt binom(BigInt N, BigInt M) { // special case if (M == 0) return BigInt(1); BigInt result = 1; iota(N-M+1, N+1).each!(n => result *= n); iota(1, M+1).each!(n => result /= n); return result; }