結果

問題 No.118 門松列(2)
ユーザー alpha_virginisalpha_virginis
提出日時 2015-06-19 21:43:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,050 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 145,028 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-21 09:49:47
合計ジャッジ時間 3,017 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,444 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

long gcd(long a, long b) {
  if( a < b ) std::swap(a, b);
  while( b != 0 ) {
    a = a % b;
    std::swap(a, b);
  }
  return a;
}

long nCr(long a, long b) {
  long w[100000] = {};
  long ret = 1;
  long temp;
  long g;

  for(int i = 0; i < b; ++i) {
    w[i] = a - i;
  }
  for(int i = 1; i <= b; ++i) {
    temp = i;
    for(int j = b-1; j >= 0; --j) {
      g = gcd(w[j], temp);
      w[j] /= g;
      temp /= g;
      if( temp == 1 ) break;
    }
  }

  for(int i = 0; i < b; ++i) {
    ret *= w[i];
    ret %= 1000000007;
  }
  return ret;
}

int main() {
  
  long N;
  long num[128] = {};
  long count;
  long ans;
  long temp;

  std::cin >> N;
  for(int i = 0; i < N; ++i) {
    std::cin >> temp;
    num[temp] += 1;
  }

  count = 0;
  for(int i = 0; i < 128; ++i) {
    if( num[i] != 0 ) {
      count += 1;
    }
  }

  ans = nCr(count, 3);
  for(int i = 0; i < 128; ++i) {
    if( num[i] != 0 ) {
      ans *= num[i];
      ans %= 1000000007;
    }
  }
  
  std::cout << ans << std::endl;
  
  return 0;
}
	
0