結果
問題 |
No.118 門松列(2)
|
ユーザー |
![]() |
提出日時 | 2015-06-29 23:32:06 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 22 ms / 5,000 ms |
コード長 | 545 bytes |
コンパイル時間 | 541 ms |
コンパイル使用メモリ | 66,416 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-09 06:59:35 |
合計ジャッジ時間 | 1,581 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <iostream> #include <map> using namespace std; typedef long long int ll; #define E 1000000007 ll ncm(ll n,ll m){ if(n<m) return 0; if(n==m) return 1; ll ans=1; for(int i=0;i<m;i++){ ans*=n-i; ans/=i+1; } return ans; } int main(){ int n; cin>>n; map<int,int> lib; int a; for(int i=0;i<n;i++){ cin>>a; lib[a]++; } ll ans=ncm(n,3); for(map<int,int>::iterator it=lib.begin();it!=lib.end();it++){ ans-=(ncm(it->second,2)*(n-(it->second))+ncm(it->second,3))%E; if(ans<0) ans+=E; } cout<<ans%E<<endl; return 0; }