結果

問題 No.118 門松列(2)
コンテスト
ユーザー diginatu
提出日時 2015-01-07 00:27:22
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
WA  
実行時間 -
コード長 716 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 585 ms
コンパイル使用メモリ 92,836 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-05 06:00:46
合計ジャッジ時間 1,522 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import std.stdio, std.conv, std.math, std.string, std.range, std.array,
       std.algorithm;

immutable MOD = 10^^9 + 7;
// コンパイル時定数よい

ulong combination(int n, int r){
	if (r == 0) return 1;
	if (r > n/2) return combination(n,n-r);
	ulong ret=1;
	for (int i = 1; i <= r; ++i)
		ret = (ret*(n-i+1)/i) % MOD;
	return ret;
}

void main(){
  readln();
  auto A = readln().strip().split().map!(to!int)().array();

  A.sort();

  long mul = 1;
  int spnum = 1;

  int k;
  while(k < A.length-1) {
    int tmul = 1;
    while(k < A.length-1 && A[k] == A[k+1]) {
      ++ tmul;
      ++ k;
    }
    spnum += 2-tmul;
    mul *= tmul%MOD;
    ++ k;
  }

  writeln((spnum.combination(3) * mul) % MOD);
}
0