結果

問題 No.616 へんなソート
ユーザー te-sh
提出日時 2017-12-18 10:11:02
言語 D
(dmd 2.109.1)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,969 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 129,568 KB
最終ジャッジ日時 2024-11-14 20:17:52
合計ジャッジ時間 927 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/format/internal/write.d(143): Error: cannot implicitly convert expression `obj` of type `const(FactorRing!(1000000007, false))` to `int`
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/format/write.d(1239): Error: template instance `std.format.internal.write.formatValueImpl!(LockingTextWriter, FactorRing!(1000000007, false), char)` error instantiating
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/format/write.d(632):        instantiated from here: `formatValue!(LockingTextWriter, FactorRing!(1000000007, false), char)`
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/stdio.d(1759):        instantiated from here: `formattedWrite!(LockingTextWriter, char, FactorRing!(1000000007, false))`
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/stdio.d(4277):        instantiated from here: `write!(FactorRing!(1000000007, false), char)`
Main.d(17):        instantiated from here: `writeln!(FactorRing!(1000000007, false))`

ソースコード

diff #
プレゼンテーションモードにする

import std.algorithm, std.conv, std.range, std.stdio, std.string;
const mod = 10^^9+7;
alias mint = FactorRing!mod;
void main()
{
auto rd = readln.split.to!(int[]), n = rd[0], k = rd[1];
auto dp = BiTree!mint(k+1);
dp[0] += mint(1);
foreach (i; 1..n)
foreach_reverse (j; 0..min(k, i*(i+1)/2)+1)
dp[j] += dp[max(0, j-i)..j];
writeln(dp[0..k+1]);
}
struct BiTree(T)
{
const size_t n;
T[] buf;
this(size_t n)
{
this.n = n;
this.buf = new T[](n + 1);
}
void opIndexOpAssign(string op: "+")(T val, size_t i)
{
++i;
for (; i <= n; i += i & -i)
buf[i] += val;
}
pure T opSlice(size_t r, size_t l) const
{
return get(l) - get(r);
}
pure size_t opDollar() const { return n; }
pure T opIndex(size_t i) const { return opSlice(i, i+1); }
private:
pure T get(size_t i) const
{
auto s = T(0);
for (; i > 0; i -= i & -i)
s += buf[i];
return s;
}
}
struct FactorRing(int m, bool pos = false)
{
version(BigEndian) {
union { long vl; struct { int vi2; int vi; } }
} else {
union { long vl; int vi; }
}
static init() { return FactorRing!(m, pos)(0); }
@property int toInt() { return vi; }
alias toInt this;
this(int v) { vi = v; }
this(int v, bool runMod) { vi = runMod ? mod(v) : v; }
this(long v) { vi = mod(v); }
ref FactorRing!(m, pos) opAssign(int v) { vi = v; return this; }
pure auto mod(int v) const
{
static if (pos) return v % m;
else return (v % m + m) % m;
}
pure auto mod(long v) const
{
static if (pos) return cast(int)(v % m);
else return cast(int)((v % m + m) % m);
}
static if (!pos) {
pure auto opUnary(string op: "-")() const { return FactorRing!(m, pos)(mod(-vi)); }
}
static if (m < int.max / 2) {
pure auto opBinary(string op: "+")(int rhs) const { return FactorRing!(m, pos)(mod(vi + rhs)); }
pure auto opBinary(string op: "-")(int rhs) const { return FactorRing!(m, pos)(mod(vi - rhs)); }
} else {
pure auto opBinary(string op: "+")(int rhs) const { return FactorRing!(m, pos)(mod(vl + rhs)); }
pure auto opBinary(string op: "-")(int rhs) const { return FactorRing!(m, pos)(mod(vl - rhs)); }
}
pure auto opBinary(string op: "*")(int rhs) const { return FactorRing!(m, pos)(mod(vl * rhs)); }
pure auto opBinary(string op)(FactorRing!(m, pos) rhs) const
if (op == "+" || op == "-" || op == "*") { return opBinary!op(rhs.vi); }
static if (m < int.max / 2) {
auto opOpAssign(string op: "+")(int rhs) { vi = mod(vi + rhs); }
auto opOpAssign(string op: "-")(int rhs) { vi = mod(vi - rhs); }
} else {
auto opOpAssign(string op: "+")(int rhs) { vi = mod(vl + rhs); }
auto opOpAssign(string op: "-")(int rhs) { vi = mod(vl - rhs); }
}
auto opOpAssign(string op: "*")(int rhs) { vi = mod(vl * rhs); }
auto opOpAssign(string op)(FactorRing!(m, pos) rhs)
if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(rhs.vi); }
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0