結果

問題 No.243 出席番号(2)
ユーザー simezi_tansimezi_tan
提出日時 2021-11-23 10:03:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,265 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 171,724 KB
実行使用メモリ 6,292 KB
最終ジャッジ日時 2023-09-07 11:51:03
合計ジャッジ時間 3,752 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,952 KB
testcase_01 AC 5 ms
5,952 KB
testcase_02 AC 4 ms
5,972 KB
testcase_03 AC 5 ms
5,960 KB
testcase_04 AC 5 ms
6,192 KB
testcase_05 AC 5 ms
5,892 KB
testcase_06 AC 5 ms
5,908 KB
testcase_07 WA -
testcase_08 AC 7 ms
5,928 KB
testcase_09 AC 5 ms
6,068 KB
testcase_10 AC 5 ms
5,896 KB
testcase_11 AC 5 ms
5,900 KB
testcase_12 WA -
testcase_13 AC 9 ms
5,936 KB
testcase_14 AC 6 ms
5,992 KB
testcase_15 AC 5 ms
6,060 KB
testcase_16 AC 6 ms
6,140 KB
testcase_17 WA -
testcase_18 AC 12 ms
5,956 KB
testcase_19 AC 7 ms
6,008 KB
testcase_20 AC 6 ms
6,060 KB
testcase_21 AC 5 ms
5,904 KB
testcase_22 WA -
testcase_23 AC 16 ms
6,132 KB
testcase_24 AC 8 ms
5,980 KB
testcase_25 AC 6 ms
5,964 KB
testcase_26 AC 6 ms
5,956 KB
testcase_27 AC 34 ms
6,124 KB
testcase_28 AC 5 ms
5,992 KB
testcase_29 AC 5 ms
6,172 KB
testcase_30 AC 5 ms
5,908 KB
testcase_31 AC 5 ms
5,948 KB
testcase_32 AC 4 ms
5,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<<",";return os<<"}";}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;
		++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;
}
0