結果

問題 No.118 門松列(2)
ユーザー te-shte-sh
提出日時 2017-01-30 15:42:57
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 460 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 88,196 KB
実行使用メモリ 6,732 KB
最終ジャッジ日時 2023-09-03 01:02:58
合計ジャッジ時間 2,369 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,508 KB
testcase_01 AC 14 ms
6,240 KB
testcase_02 AC 13 ms
5,540 KB
testcase_03 AC 14 ms
6,732 KB
testcase_04 AC 13 ms
5,412 KB
testcase_05 AC 14 ms
6,188 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 13 ms
5,956 KB
testcase_10 AC 4 ms
4,384 KB
testcase_11 AC 5 ms
4,384 KB
testcase_12 AC 3 ms
4,384 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 13 ms
6,428 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 8 ms
5,112 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 7 ms
4,504 KB
testcase_20 AC 7 ms
5,108 KB
testcase_21 AC 11 ms
6,108 KB
testcase_22 AC 4 ms
4,384 KB
testcase_23 AC 11 ms
6,100 KB
testcase_24 AC 5 ms
4,864 KB
testcase_25 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
}
0