結果

問題 No.118 門松列(2)
ユーザー te-shte-sh
提出日時 2016-08-30 21:13:04
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 556 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 109,380 KB
実行使用メモリ 6,700 KB
最終ジャッジ日時 2023-09-02 21:37:49
合計ジャッジ時間 1,970 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 17 ms
6,700 KB
testcase_02 AC 16 ms
6,208 KB
testcase_03 AC 15 ms
5,736 KB
testcase_04 AC 16 ms
5,956 KB
testcase_05 AC 17 ms
5,924 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 16 ms
6,424 KB
testcase_10 AC 5 ms
4,372 KB
testcase_11 AC 7 ms
5,092 KB
testcase_12 AC 4 ms
4,372 KB
testcase_13 AC 3 ms
4,368 KB
testcase_14 AC 15 ms
6,120 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 9 ms
4,812 KB
testcase_17 AC 3 ms
4,372 KB
testcase_18 AC 6 ms
4,368 KB
testcase_19 AC 8 ms
4,372 KB
testcase_20 AC 9 ms
4,368 KB
testcase_21 AC 12 ms
4,848 KB
testcase_22 AC 5 ms
4,372 KB
testcase_23 AC 12 ms
4,368 KB
testcase_24 AC 6 ms
4,372 KB
testcase_25 AC 8 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range;
import std.string, std.conv;
import std.math, std.bigint, std.bitmanip, std.random;
import std.stdio, std.typecons;

const auto mod = 10 ^^ 9 + 7;

void main()
{
  auto n = readln.chomp.to!ulong;
  auto ai = readln.split.map!(to!int).array;
  ai.sort();
  auto gi = ai.group;

  auto r = n * (n - 1) * (n - 2) / 6;
  foreach (g; gi) {
    auto c = g[1].to!long;
    if (c >= 2)
      r -= c * (c - 1) / 2 * (n - c);
    if (c >= 3)
      r -= c * (c - 1) * (c - 2) / 6;
  }

  writeln(r % mod);
}
0