結果

問題 No.118 門松列(2)
ユーザー betit0919betit0919
提出日時 2019-07-07 20:08:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 1,288 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 108,260 KB
実行使用メモリ 15,632 KB
最終ジャッジ日時 2024-04-15 12:18:45
合計ジャッジ時間 2,435 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
15,392 KB
testcase_01 AC 24 ms
15,340 KB
testcase_02 AC 25 ms
15,412 KB
testcase_03 AC 25 ms
15,460 KB
testcase_04 AC 27 ms
15,576 KB
testcase_05 AC 24 ms
15,632 KB
testcase_06 AC 14 ms
15,476 KB
testcase_07 AC 14 ms
15,264 KB
testcase_08 AC 14 ms
15,520 KB
testcase_09 AC 23 ms
15,520 KB
testcase_10 AC 17 ms
15,492 KB
testcase_11 AC 17 ms
15,476 KB
testcase_12 AC 16 ms
15,400 KB
testcase_13 AC 17 ms
15,516 KB
testcase_14 AC 23 ms
15,412 KB
testcase_15 AC 15 ms
15,348 KB
testcase_16 AC 19 ms
15,264 KB
testcase_17 AC 15 ms
15,452 KB
testcase_18 AC 17 ms
15,320 KB
testcase_19 AC 19 ms
15,260 KB
testcase_20 AC 19 ms
15,532 KB
testcase_21 AC 21 ms
15,508 KB
testcase_22 AC 17 ms
15,508 KB
testcase_23 AC 22 ms
15,580 KB
testcase_24 AC 18 ms
15,436 KB
testcase_25 AC 19 ms
15,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()


const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FAC(int n){
  return fac[n];
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  COMinit();
  int N;
  cin>>N;
  map<int,int> mp;
  for(int i=0;i<N;i++){
    int A;cin>>A;
    mp[A]++;
  }
  ll ans=COM(N,3);
  for(auto e : mp){
    ans-=COM(e.second,2)*(N-e.second)%MOD;
    ans+=MOD;
    ans-=COM(e.second,3);
    ans+=MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
}
0