結果
| 問題 |
No.93 ペガサス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-10 17:45:30 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,354 bytes |
| コンパイル時間 | 628 ms |
| コンパイル使用メモリ | 126,556 KB |
| 最終ジャッジ日時 | 2024-11-14 20:11:47 |
| 合計ジャッジ時間 | 1,392 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、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, true))` 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, true), char)` error instantiating /home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/format/write.d(632): instantiated from here: `formatValue!(LockingTextWriter, FactorRing!(1000000007, true), char)` /home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/stdio.d(1759): instantiated from here: `formattedWrite!(LockingTextWriter, char, FactorRing!(1000000007, true))` /home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/stdio.d(4277): instantiated from here: `write!(FactorRing!(1000000007, true), char)` Main.d(53): instantiated from here: `writeln!(FactorRing!(1000000007, true))`
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string;
const mod = 10 ^^ 9 + 7;
alias FactorRing!(mod, true) mint;
void main()
{
auto n = readln.chomp.to!int;
if (n == 1) {
writeln(1);
return;
}
auto dp = new mint[][][][](n+1, n+1, 2, 2);
dp[2][0][0][0] = mint(2);
foreach (i; 3..n+1)
foreach (j; 0..i) {
auto v11 = dp[i-1][j][1][1];
if (v11 > 0) {
dp[i][j][1][1] += v11; // split x-1,x-3
dp[i][j-1][0][0] += v11; // split x,x-2
dp[i][j-1][1][0] += v11 * (j-2); // split other
dp[i][j+1][1][1] += v11; // add next x-1
dp[i][j][1][0] += v11 * (i-j-1);
}
auto v01 = dp[i-1][j][0][1];
if (v01 > 0) {
dp[i][j-1][0][0] += v01; // split x,x-2
dp[i][j-1][1][0] += v01 * (j-1); // split other
dp[i][j+1][1][1] += v01 * 2; // add next x-1
dp[i][j][1][0] += v01 * (i-j-2);
}
auto v10 = dp[i-1][j][1][0];
if (v10 > 0) {
dp[i][j][0][1] += v10; // split x-1,x-3
dp[i][j-1][0][0] += v10 * (j-1); // split other
dp[i][j+1][0][1] += v10; // add next x-1
dp[i][j][0][0] += v10 * (i-j-1);
}
auto v00 = dp[i-1][j][0][0];
if (v00 > 0) {
if (j > 0) dp[i][j-1][0][0] += v00 * j; // split
dp[i][j+1][0][1] += v00 * 2; // add next x-1
dp[i][j][0][0] += v00 * (i-j-2);
}
}
writeln(dp[n][0][0][0]);
}
struct FactorRing(int m, bool pos = false)
{
version(BigEndian) {
union { long vl; struct { int vi2; int vi; } }
} else {
union { long vl; int vi; }
}
@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 (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); }
}