結果

問題 No.243 出席番号(2)
ユーザー 沙耶花沙耶花
提出日時 2022-03-17 19:58:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 4,192 ms
コンパイル使用メモリ 256,764 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 18:59:14
合計ジャッジ時間 4,820 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001


int main(){
	
	int n;
	cin>>n;
	
	vector<int> cnt(5000,0);
	rep(i,n){
		int a;
		cin>>a;
		cnt[a] ++;
	}
	
	vector<mint> dp(n+1,0);
	dp[0] = 1;
	
	rep(i,5000){
		if(cnt[i]==0)continue;
		vector<mint> ndp(n+1,0);
		rep(j,dp.size()){
			if(dp[j]==0)continue;
			ndp[j] += dp[j];
			if(i<n && j+1<dp.size()){
				ndp[j+1] += dp[j] * cnt[i];
			}
		}
		swap(dp,ndp);
	}
	mint c = 1;
	rep(i,n+1){
		dp[n-i] *= c;
		c *= i+1;
	}
	mint ans = 0;
	rep(i,n+1){
		if(i%2 == 0)ans += dp[i];
		else ans -= dp[i];
	}
	cout<<ans.val()<<endl;
	return 0;
}
0