結果
| 問題 |
No.118 門松列(2)
|
| ユーザー |
tkzw_21
|
| 提出日時 | 2015-01-07 00:25:50 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 5,000 ms |
| コード長 | 934 bytes |
| コンパイル時間 | 987 ms |
| コンパイル使用メモリ | 83,432 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-09 06:50:49 |
| 合計ジャッジ時間 | 2,143 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#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;
}
tkzw_21