結果

問題 No.243 出席番号(2)
ユーザー Asdf_QwertyZAsdf_QwertyZ
提出日時 2020-05-23 19:25:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,206 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 89,644 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 06:48:52
合計ジャッジ時間 8,715 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 5 ms
6,944 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 209 ms
6,940 KB
testcase_04 AC 212 ms
6,940 KB
testcase_05 AC 214 ms
6,944 KB
testcase_06 AC 222 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 307 ms
6,940 KB
testcase_09 AC 330 ms
6,944 KB
testcase_10 AC 303 ms
6,944 KB
testcase_11 AC 323 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 252 ms
6,944 KB
testcase_14 AC 255 ms
6,944 KB
testcase_15 AC 300 ms
6,940 KB
testcase_16 AC 360 ms
6,940 KB
testcase_17 WA -
testcase_18 AC 244 ms
6,940 KB
testcase_19 AC 263 ms
6,944 KB
testcase_20 AC 274 ms
6,940 KB
testcase_21 AC 273 ms
6,940 KB
testcase_22 WA -
testcase_23 AC 288 ms
6,944 KB
testcase_24 AC 287 ms
6,940 KB
testcase_25 AC 282 ms
6,940 KB
testcase_26 AC 312 ms
6,940 KB
testcase_27 AC 302 ms
6,944 KB
testcase_28 AC 6 ms
6,940 KB
testcase_29 AC 6 ms
6,944 KB
testcase_30 AC 7 ms
6,944 KB
testcase_31 AC 9 ms
6,944 KB
testcase_32 AC 9 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N;
ll A[5010];
std::map<ll, ll> C;
mint dp[2][5010];
combination comb( 10000 );

int main()
{
  std::cin >> N;

  rep( i, N )
    std::cin >> A[i], ++C[A[i]];

  ll sum = 0;

  dp[0][0] = 1;

  rep( i, 5000 ) 
  {
    rep( k, sum+2 )
      dp[(i+1)&1][k] = 0;

    rep( k, sum+1 )
    {
      if( C.count(i) )
        dp[(i+1)&1][k+1] += dp[i&1][k]*C[i];
      
      dp[(i+1)&1][k] += dp[i&1][k];
    }

    sum += C[i];
  }

  mint ans = 0;

  rep( k, N+1 )
  {

    ans += dp[0][k]*comb.fact[N-k]*(k&1 ? -1 : 1);
  }

  std::cout << ans.x << std::endl;

  return 0;
}
0