結果
| 問題 |
No.118 門松列(2)
|
| ユーザー |
nanophoto12
|
| 提出日時 | 2015-12-30 23:53:36 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,814 bytes |
| コンパイル時間 | 681 ms |
| コンパイル使用メモリ | 82,124 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-19 08:52:04 |
| 合計ジャッジ時間 | 1,714 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 WA * 24 |
ソースコード
#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
#define FOR(x,y) for(int x = 0;x < y;x++)
#define LLI long long int
template<int um> class UF {
public:
vector<int> par,rank,cnt;
UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
void reinit() {FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
int count(int x) { return cnt[operator[](x)];}
int operator()(int x,int y) {
if((x=operator[](x))==(y=operator[](y))) return x;
cnt[y]=cnt[x]=cnt[x]+cnt[y];
if(rank[x]>rank[y]) return par[x]=y;
rank[x]+=rank[x]==rank[y]; return par[y]=x;
}
};
LLI combination(int n){
return (LLI)n*(n-1)*(n-2)/6;
}
LLI combination2(int n){
return (LLI)n*(n-1)/2;
}
LLI calculate(int n,int m){
if(m==2)return n-2;
else{
return combination2(m)*(n-m)+combination(m);
}
}
int main() {
int n;
cin >> n;
map<int,int> data;
vector<int> buffer;
FOR(i, n)
{
int value;
cin >> value;
if(data.find(value) == data.end())
{
data[value] = 1;
buffer.push_back(value);
}
else
{
data[value]++;
}
}
const LLI mod = 1000000007;
LLI count = buffer.size();
count *= buffer.size()-1;
count *= buffer.size()-2;
count /= 6;
LLI remove = 0;
for(auto iterator = data.begin(); iterator != data.end();iterator++)
{
remove += calculate((int)buffer.size(), iterator->second);
}
LLI result = (count - remove) % mod;
cout << result << endl;
return 0;
}
nanophoto12