結果

問題 No.118 門松列(2)
ユーザー youjo_yamioti
提出日時 2018-12-09 04:53:47
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 887 bytes
コンパイル時間 1,655 ms
コンパイル使用メモリ 168,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-16 05:43:02
合計ジャッジ時間 2,723 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int memo[100000] = {0};
int sum(int N,vector<int> vec){
    if(N == 1) return memo[0] = vec[0];
    else{
        if(memo[N-1] != 0) return memo[N-1];
        return memo[N-1] = vec[N-1] + sum(N-1,vec);
    }
}
long int T(int N,vector<int> vec){
    if(N == 2) return vec[0] * vec[1];
    else{
        return T(N-1,vec) + sum(N-1,vec) * vec[N-1];    
    }
}

long int S(int N,vector<int> vec){
    if(N == 3) return ((long int)vec[0] * vec[1] * vec[2]) % 1000000007;
    else return (S(N-1,vec) + T(N-1,vec) * vec[N-1]) % 1000000007;
}

int main(){
    int N;
    cin >> N;
    vector<int> L(N,0);
    map<int,int> m;
    for(int i=0;i<N;i++){
        cin >> L[i];
        m[L[i]]++;
    } 
    vector<int> vec = {};
    for(auto i : m){
        vec.push_back(i.second);
    }

    cout << S(vec.size(),vec) << endl;

    return 0;

    
}
0