結果

問題 No.243 出席番号(2)
ユーザー pekempeypekempey
提出日時 2015-09-30 14:34:47
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 990 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 146,024 KB
実行使用メモリ 175,432 KB
最終ジャッジ日時 2023-09-27 00:31:19
合計ジャッジ時間 9,184 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 12 ms
42,752 KB
testcase_04 AC 11 ms
42,564 KB
testcase_05 AC 11 ms
42,580 KB
testcase_06 AC 11 ms
42,564 KB
testcase_07 AC 12 ms
42,580 KB
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
#define rng(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;
ll dp[5050][5050];
ll fact[5050];

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	rep (i, N) {
		int A;
		cin >> A;
		a[A]++;
	}
	fact[0] = 1;
	rep2 (i, 1, 5050) fact[i] = (fact[i - 1] * i) % mod;
	dp[0][0] = 1;
	dp[0][1] = a[0];
	rep2 (i, 1, N) rep (j, i + 2) {
		if (j == 0) dp[i][j] = 1;
		else {
			dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1] * a[i]) % mod;
		}
	}
	ll ans = 0;
	rep2 (i, 1, N + 1) {
		ll sign = i & 1 ? 1 : -1;
		ans += sign * dp[N - 1][i] * fact[N - i] % mod;
	}
	ans = (fact[N] - ans) % mod;
	ans += mod; ans %= mod;
	cout << ans << endl;
	return 0;
}
0