結果
| 問題 |
No.171 スワップ文字列(Med)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-07 12:01:11 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,306 bytes |
| コンパイル時間 | 1,339 ms |
| コンパイル使用メモリ | 129,700 KB |
| 最終ジャッジ日時 | 2024-11-14 19:57:40 |
| 合計ジャッジ時間 | 1,731 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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!573)` 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!573, char)` error instantiating /home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/format/write.d(632): instantiated from here: `formatValue!(LockingTextWriter, FactorRing!573, char)` /home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/stdio.d(1759): instantiated from here: `formattedWrite!(LockingTextWriter, char, FactorRing!573)` /home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/stdio.d(4277): instantiated from here: `write!(FactorRing!573, char)` Main.d(29): instantiated from here: `writeln!(FactorRing!573)`
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string;
alias FactorRing!573 mint;
void main()
{
auto s = readln.chomp;
auto hi = new int[](26);
foreach (c; s) ++hi[c - 'A'];
hi.sort!"a > b";
auto dp = new mint[][](s.length + 2, s.length + 1);
foreach (n; 1..s.length + 2) dp[n][0] = mint(1);
foreach (m; 0..s.length + 1) dp[1][m] = mint(1);
foreach (n; 2..s.length + 2)
foreach (m; 1..s.length + 1)
dp[n][m] = dp[n-1][m] + dp[n][m - 1];
auto r = mint(1);
auto l = hi.front;
foreach (h; hi.drop(1)) {
if (h == 0) break;
r = r * dp[l + 1][h];
l += h;
}
writeln(r - 1);
}
struct FactorRing(int m) {
long v;
@property int toInt() { return v.to!int; }
alias toInt this;
this(T)(T _v) { v = mod(_v); }
ref FactorRing!m opAssign(int _v) {
v = mod(_v);
return this;
}
auto mod(long _v) { return _v > 0 ? _v % m : ((_v % m) + m) % m; }
auto opBinary(string op: "+")(FactorRing!m rhs) { return FactorRing!m(v + rhs.v); }
auto opBinary(string op: "-")(FactorRing!m rhs) { return FactorRing!m(v - rhs.v); }
auto opBinary(string op: "*")(FactorRing!m rhs) { return FactorRing!m(v * rhs.v); }
auto opBinary(string op)(int rhs)
if (op == "+" || op == "-" || op == "*") { return opBinary!op(FactorRing!m(rhs)); }
}