結果

問題 No.118 門松列(2)
ユーザー tkzw_21tkzw_21
提出日時 2015-01-07 00:25:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 934 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 83,404 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-30 11:30:52
合計ジャッジ時間 2,379 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#define INF INT_MAX / 2
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef long long ll;

long long combi3(int n){
	return (long long)n*(n-1)*(n-2)/6;
}
long long combi2(int n){
	return (long long)n*(n-1)/2;
}

long long func(int n,int m){
	if(m==2)return n-2;
	else{
		return combi2(m)*(n-m)+combi3(m);
	}
}

int main(void) {
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	map<int,int>counter;
	for(int i=0;i<n;i++){
		counter[a[i]]++;
	}

	int cnt = 0;
	long long tmp = 0;
	auto it = counter.begin();
	for(;it!=counter.end();it++){
		if(it->second > 1){
			tmp += func(n,it->second);
		}
		cnt++;
	}

	long long ans = combi3(n) - tmp;
	cout << ans%MOD << endl;
}
0