結果

問題 No.243 出席番号(2)
ユーザー pekempeypekempey
提出日時 2015-09-30 14:39:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,006 bytes
コンパイル時間 1,323 ms
コンパイル使用メモリ 145,104 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-27 00:31:40
合計ジャッジ時間 3,367 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,388 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 8 ms
4,384 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 15 ms
4,380 KB
testcase_17 AC 14 ms
4,384 KB
testcase_18 AC 24 ms
4,380 KB
testcase_19 AC 24 ms
4,376 KB
testcase_20 AC 24 ms
4,380 KB
testcase_21 AC 24 ms
4,376 KB
testcase_22 AC 24 ms
4,380 KB
testcase_23 AC 36 ms
4,380 KB
testcase_24 AC 36 ms
4,376 KB
testcase_25 AC 36 ms
4,380 KB
testcase_26 AC 36 ms
4,380 KB
testcase_27 AC 36 ms
4,376 KB
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,380 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[2][5050];
ll fact[5050];
ll a[5050];

int main() {
	int N;
	cin >> 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 % 2][j] = 1;
		else {
			dp[i % 2][j] = (dp[(i + 1) % 2][j] + dp[(i + 1) % 2][j - 1] * a[i]) % mod;
		}
	}
	ll ans = 0;
	rep2 (i, 1, N + 1) {
		ll sign = i & 1 ? 1 : -1;
		ans += sign * dp[(N + 1) % 2][i] * fact[N - i] % mod;
	}
	ans = (fact[N] - ans) % mod;
	ans += mod; ans %= mod;
	cout << ans << endl;
	return 0;
}
0