結果

問題 No.243 出席番号(2)
ユーザー nxterunxteru
提出日時 2018-11-01 21:53:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 2,780 ms
コンパイル使用メモリ 164,972 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 16:39:09
合計ジャッジ時間 3,591 ms
ジャッジサーバーID
(参考情報)
judge7 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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