結果

問題 No.243 出席番号(2)
ユーザー Kmcode1Kmcode1
提出日時 2015-07-11 00:30:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,835 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 98,928 KB
実行使用メモリ 55,900 KB
最終ジャッジ日時 2023-09-22 10:32:40
合計ジャッジ時間 2,178 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,960 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,396 KB
testcase_08 AC 7 ms
6,932 KB
testcase_09 AC 3 ms
4,652 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 9 ms
8,212 KB
testcase_13 AC 12 ms
9,740 KB
testcase_14 AC 4 ms
4,876 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 25 ms
16,260 KB
testcase_18 AC 19 ms
13,152 KB
testcase_19 AC 4 ms
5,416 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 56 ms
31,656 KB
testcase_23 AC 27 ms
17,260 KB
testcase_24 AC 6 ms
6,356 KB
testcase_25 AC 4 ms
4,640 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 106 ms
55,900 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_map>
using namespace std;
#define MOD 1000000007
#define MAX 5001
int cnt[MAX];
int n;
vector<long long int> cn;
int dp[MAX][MAX];
long long int k[MAX];
long long int ppow(long long int i, long long int j){
	long long int r = 1LL;
	while (j){
		if ((j & 1LL)){
			r *= i;
			r %= MOD;
		}
		i *= i;
		i %= MOD;
		j >>= 1LL;
	}
	return r;
}
int main(){
	scanf("%d", &n);
	k[0] = 1LL;
	for (int i = 1; i < MAX; i++){
		k[i] = k[i - 1];
		k[i] *= (long long int)(i);
		k[i] %= MOD;
	}
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		cnt[a]++;
	}
	int countt = 0;
	for (int i = 0; i < MAX; i++){
		if (cnt[i]){
			if (i >= n){
				countt += cnt[i];
				continue;
			}
			cn.push_back(cnt[i]);
		}
	}
	dp[0][0] = 1LL;
	for (int i = 0; i < cn.size(); i++){
		for (int j = 0; j <= cn.size(); j++){
			dp[i + 1][j+1] += (dp[i][j]*cn[i])%MOD;
			dp[i + 1][j] += dp[i][j];
			dp[i + 1][j + 1] %= MOD;
			dp[i + 1][j] %= MOD;
		}
	}
	long long int ans = 0;
	for (int i = 0; i <= cn.size(); i++){
		long long int g = 1LL;
		if (i % 2 == 1LL){
			g = -1LL;
		}
		long long int way = dp[cn.size()][i] * k[n - i];// *ppow(k[n - i + countt - 1], MOD - 2);
		way %= MOD;
		if (g == -1){
			ans += MOD - way;
			ans %= MOD;
		}
		else{
			ans += way;
			ans %= MOD;
		}
	}
	//ans *= k[countt];
	//ans %= MOD;
	printf("%lld\n",ans);
	return 0;
	return 0;
}
0