結果

問題 No.118 門松列(2)
ユーザー ty70ty70
提出日時 2015-06-01 11:02:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 1,949 bytes
コンパイル時間 1,016 ms
コンパイル使用メモリ 97,960 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 12:58:15
合計ジャッジ時間 2,566 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
5,248 KB
testcase_01 AC 33 ms
5,376 KB
testcase_02 AC 33 ms
5,376 KB
testcase_03 AC 34 ms
5,376 KB
testcase_04 AC 34 ms
5,376 KB
testcase_05 AC 34 ms
5,376 KB
testcase_06 AC 22 ms
5,376 KB
testcase_07 AC 23 ms
5,376 KB
testcase_08 AC 23 ms
5,376 KB
testcase_09 AC 33 ms
5,376 KB
testcase_10 AC 25 ms
5,376 KB
testcase_11 AC 26 ms
5,376 KB
testcase_12 AC 24 ms
5,376 KB
testcase_13 AC 23 ms
5,376 KB
testcase_14 AC 33 ms
5,376 KB
testcase_15 AC 22 ms
5,376 KB
testcase_16 AC 28 ms
5,376 KB
testcase_17 AC 24 ms
5,376 KB
testcase_18 AC 25 ms
5,376 KB
testcase_19 AC 27 ms
5,376 KB
testcase_20 AC 28 ms
5,376 KB
testcase_21 AC 31 ms
5,376 KB
testcase_22 AC 25 ms
5,376 KB
testcase_23 AC 30 ms
5,376 KB
testcase_24 AC 26 ms
5,376 KB
testcase_25 AC 27 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 ){
	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;
}
0