結果
問題 | No.243 出席番号(2) |
ユーザー |
![]() |
提出日時 | 2021-11-23 10:05:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 2,275 bytes |
コンパイル時間 | 1,519 ms |
コンパイル使用メモリ | 174,164 KB |
実行使用メモリ | 6,144 KB |
最終ジャッジ日時 | 2024-06-25 06:01:31 |
合計ジャッジ時間 | 2,615 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h>#define rep(i,n) for(int i=0;i<(int)n;i++)#define all(c) (c).begin(),(c).end()#define pb push_back#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);using namespace std;namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";returnos<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;const int mod = 1e9 + 7;const int MX = 110000;ll inv[MX], f[MX], invf[MX];void calc(){inv[0] = inv[1] = f[0] = f[1] = invf[0] = invf[1] = 1;for (int i = 2; i < MX; i++){inv[i] = mod - mod / i * inv[mod % i] % mod;f[i] = f[i - 1] * i % mod;invf[i] = invf[i - 1] * inv[i] % mod;}}inline ll C(ll n, ll k){return f[n] * invf[k] % mod * invf[n - k] % mod;}int dp[5001];int main(){cin.tie(0); cin.sync_with_stdio(0);calc();int n; cin >> n;map<int, int> cnt;rep(i, n){int a; cin >> a;if(a < n) ++cnt[a];}dp[0] = 1;for(pi p : cnt){for(int i = n; i >= 0; i--) if(dp[i]){dp[i + 1] = (dp[i + 1] + dp[i] * (ll)p.second) % mod;}}ll ans = 0;rep(i, n + 1) ans += (mod + (i % 2 ? -1 : 1) * dp[i]) * f[n - i] % mod;cout << ans % mod << endl;return 0;}