結果
| 問題 |
No.118 門松列(2)
|
| ユーザー |
ty70
|
| 提出日時 | 2015-06-01 11:08:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 5,000 ms |
| コード長 | 1,973 bytes |
| コンパイル時間 | 805 ms |
| コンパイル使用メモリ | 96,488 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-09 06:59:14 |
| 合計ジャッジ時間 | 2,367 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cstdlib> // require abs exit atof atoi
#include <cstdio> // require scanf printf
#include <functional>
#include <numeric> // require accumulate
#include <cmath> // require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip> // require setw
#include <sstream> // require stringstream
#include <cstring> // require memset
#include <cctype> // require tolower, toupper
#include <fstream> // require freopen
#include <ctime> // require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = (ll)1e9 + 7LL;
const int MAX_N = (int)1e5 + 5;
ll fact[MAX_N], rfact[MAX_N];
ll extgcd (ll a, ll b, ll &x, ll &y ){
if (b == 0 ){x = 1LL; y = 0LL; return a; }
ll g = extgcd (b, a%b, y, x ); y -= a/b*x;
return g;
}
ll mod_inv (ll a, ll M ){
ll x, y;
extgcd (a, M, x, y );
return (M+x%M)%M;
}
void init_mod (void ){
fact[0] = rfact[0] = 1LL;
for (int i = 1; i < MAX_N; i++ ){
fact[i] = (fact[i-1]*(ll)i)%MOD;
rfact[i] = (rfact[i-1]*mod_inv((ll)i,MOD))%MOD;
} // end for
}
ll comb (int n, int k ){
if (n < k ) return 0LL;
return ((fact[n]*rfact[n-k])%MOD)*rfact[k]%MOD;
}
int main()
{
init_mod();
ios_base::sync_with_stdio(0);
int N; cin >> N;
map<int,int> cnt; cnt.clear();
rep (i, N ){
int ain; cin >> ain;
cnt[ain]++;
} // end rep
ll res = (ll)comb (N, 3 );
ll curr = 0LL;
map<int,int>::iterator it = cnt.begin();
for (; it != cnt.end(); it++ ){
int m = (*it).second;
if (m >= 2 ){
curr = (curr + comb(m, 2 )*comb(N-m, 1 ) ) % MOD;
curr = (curr + comb(m, 3 ) ) % MOD;
} // end for
} // end for
res = (res - curr + MOD ) % MOD;
cout << res << endl;
return 0;
}
ty70