結果

問題 No.118 門松列(2)
ユーザー GrayCoder
提出日時 2018-08-14 17:46:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 665 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 174,416 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-24 08:51:32
合計ジャッジ時間 2,733 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  long N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  map <int, long> mp;
  for (int i = 0; i < N; i++) {
    mp[A[i]]++;
  }

  long cnt, mod;
  mod = 1000000007;
  cnt = (N * (N - 1) * (N - 2)) / 6;
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    long n = itr->second;
    if (n > 2) cnt -= (n * (n - 1) * (n - 2)) / 6;
    if (n > 1) cnt -= (n * (n - 1)) / 2 * (N - n);
  }
  cout << cnt % mod << endl;
  return 0;
}
0