結果

問題 No.118 門松列(2)
ユーザー nanophoto12nanophoto12
提出日時 2015-12-30 23:55:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 1,722 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 13:19:03
合計ジャッジ時間 2,095 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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 = combination(n);
    LLI remove = 0;
    for(auto iterator = data.begin(); iterator != data.end();iterator++)
    {
        remove += calculate(n, iterator->second);
    }
    LLI result = (count - remove) % mod;
    cout << result << endl;
    return 0;
}
0