結果
問題 | No.243 出席番号(2) |
ユーザー |
![]() |
提出日時 | 2018-10-14 18:32:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 950 bytes |
コンパイル時間 | 1,026 ms |
コンパイル使用メモリ | 87,652 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 18:20:51 |
合計ジャッジ時間 | 2,500 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include<iostream>#include<string>#include<algorithm>#include<vector>#include<iomanip>#include<math.h>#include<complex>#include<queue>#include<deque>#include<stack>#include<map>#include<set>#include<bitset>#include<functional>using namespace std;#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )#define rep(i,n) REP(i,0,n)typedef long long ll;typedef pair<int,int> pint;typedef pair<ll,int> pli;const int inf=1e9+7;const ll longinf=1LL<<60 ;const ll mod=1e9+7 ;ll dp[6000];ll cnt[6000];int main(){int n;cin>>n;rep(i,n){int x;cin>>x;++cnt[x];}dp[0]=1;rep(i,n)for(int j=n;j>=0;--j){(dp[j+1]+=dp[j]*cnt[i])%=mod;}ll fact[6000];fact[0]=1;rep(i,n)fact[i+1]=fact[i]*(i+1)%mod;ll ans=0;rep(j,n+1){if(j%2==0)ans+=dp[j]*fact[n-j];else ans+=mod-dp[j]*fact[n-j]%mod;ans%=mod;}cout<<ans<<endl;return 0;}