結果

問題 No.243 出席番号(2)
ユーザー Kmcode1Kmcode1
提出日時 2015-07-10 23:46:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,545 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 98,300 KB
実行使用メモリ 55,928 KB
最終ジャッジ日時 2023-09-22 10:24:15
合計ジャッジ時間 2,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
5,048 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 6 ms
6,984 KB
testcase_09 AC 3 ms
4,452 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 9 ms
9,808 KB
testcase_14 AC 3 ms
4,944 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 14 ms
13,264 KB
testcase_19 AC 4 ms
5,528 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 19 ms
17,236 KB
testcase_24 AC 5 ms
6,456 KB
testcase_25 AC 3 ms
4,476 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 72 ms
55,928 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 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 5003
int cnt[MAX];
int n;
vector<long long int> v;
vector<long long int> cn;
long long int dp[MAX][MAX];
long long int k[MAX];
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]++;
	}
	for (int i = 0; i < MAX; i++){
		if (cnt[i]){
			v.push_back(i);
			cn.push_back(cnt[i]);
		}
	}
	dp[0][0] = 1LL;
	for (int i = 0; i < v.size(); i++){
		for (int j = 0; j <= i; j++){
			dp[i + 1][j+1] += dp[i][j]*cn[i];
			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 <= v.size(); i++){
		long long int g = 1LL;
		if (i % 2 == 1LL){
			g = -1LL;
		}
		long long int way = dp[v.size()][i] * k[n - i];
		way %= MOD;
		way *= g;
		while (way < 0){
			way += MOD;
		}
		ans += way;
		ans %= MOD;
	}
	if (ans < 0){
		return 1;
	}
	printf("%lld\n", ans);
	return 0;
	return 0;
}
0