結果

問題 No.243 出席番号(2)
ユーザー chocoruskchocorusk
提出日時 2018-10-14 20:45:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 20:19:31
合計ジャッジ時間 2,423 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
	int n;
  cin>>n;
  int ct[5001]={};
  for(int i=0; i<n; i++){
    int a; cin>>a;
    ct[a]++;
  }
  ll dp[2][5001]={};
  dp[0][0]=1;
  for(int i=0; i<n; i++){
    for(int j=0; j<=n; j++){
      dp[(i+1)%2][j]=dp[i%2][j];
      if(j>0) dp[(i+1)%2][j]+=(ll)ct[i]*dp[i%2][j-1];
      dp[(i+1)%2][j]%=MOD;
    }
  }
  ll f[5001];
  f[0]=1;
  for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
  ll ans=f[n];
  for(int i=1; i<=n; i++){
    if(i%2){
      ans-=(f[n-i]*dp[n%2][i]%MOD);
      ans+=MOD;
      ans%=MOD;
    }else{
      ans+=(f[n-i]*dp[n%2][i]%MOD);
      ans%=MOD;
    }
  }
  cout<<ans<<endl;
	return 0;
}
0