結果
| 問題 |
No.118 門松列(2)
|
| ユーザー |
|
| 提出日時 | 2017-01-30 15:42:57 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 13 ms / 5,000 ms |
| コード長 | 460 bytes |
| コンパイル時間 | 966 ms |
| コンパイル使用メモリ | 101,784 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 06:43:14 |
| 合計ジャッジ時間 | 2,289 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string;
const auto p = 10L ^^ 9 + 7;
void main()
{
auto n = readln.chomp.to!size_t;
auto ai = readln.split.to!(long[]);
long[long] cnt;
foreach (a; ai) ++cnt[a];
auto nl = n.to!long;
auto r = nl * (nl - 1) * (nl - 2) / 6;
foreach (c; cnt.byValue) {
if (c >= 2)
r -= c * (c - 1) / 2 * (nl - c);
if (c >= 3)
r -= c * (c - 1) * (c - 2) / 6;
}
writeln(r % p);
}