結果

問題 No.243 出席番号(2)
ユーザー nxterunxteru
提出日時 2018-11-01 21:50:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 554 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 168,428 KB
実行使用メモリ 198,952 KB
最終ジャッジ日時 2024-04-30 11:34:13
合計ジャッジ時間 4,080 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 11 ms
42,496 KB
testcase_04 AC 10 ms
42,512 KB
testcase_05 AC 11 ms
42,544 KB
testcase_06 AC 10 ms
42,592 KB
testcase_07 AC 11 ms
42,616 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 3 ms
6,948 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define M 1000000007
ll n,dp[5005][5005],c[5005],k[5005],ans;
int main(void){
    cin>>n;
    k[0]=1;
    for(ll i=1;i<=n;i++)k[i]=k[i-1]*i%M;
    for(int i=0;i<n;i++){
		ll a;
		cin>>a;
		c[a]++;
	}
	dp[0][0]=1;
	dp[0][1]=c[0];
	for(int i=1;i<n;i++){
		dp[i][0]=1;
		for(int j=1;j<=i+1;j++){
			dp[i][j]=(dp[i-1][j]+dp[i-1][j-1]*c[i])%M;
		}
	}
	ans=k[n];
	for(int i=1;i<=n;i++){
		if(i%2)ans=(ans+M-dp[n-1][i]*k[n-i]%M)%M;
		else ans=(ans+dp[n-1][i]*k[n-i])%M;
	}
	cout<<ans<<endl;
}
0