結果

問題 No.243 出席番号(2)
ユーザー shogier1shogier1
提出日時 2019-10-11 01:11:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,385 bytes
コンパイル時間 1,696 ms
コンパイル使用メモリ 98,280 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-14 11:00:20
合計ジャッジ時間 10,407 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <cstdint>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
const ll INFL = 1LL << 60;//10^18 = 2^60
int MOD = 1000000007;

int kai[5010];

int N;
vector<int> A;
int dp[2][5010];
void solve(){
  kai[0] = 1;
  rep(i, 5009) kai[i+1] = kai[i] * (i+1) % MOD;
  sort(A.begin(), A.end());
  dp[0][0] = 1;
  int s = 0;
  rep(i, 5005){
    int cnt = 0;
    while(A[s] == i){
      s++;
      cnt++;
    }
    rep(j, 5005){
      dp[(i+1)&1][j] += dp[i&1][j];
      dp[(i+1)&1][j] %= MOD;
      dp[(i+1)&1][j+1] += dp[i&1][j] * cnt % MOD;
      dp[(i+1)&1][j+1] %= MOD;
    }
    rep(j, 5005){
      dp[i&1][j] = 0;
    }
  }
  int ans = 0;
  rep(j, N+1){
    if(j & 1) ans += MOD - kai[N-j] * dp[1][j] % MOD;
    else ans += kai[N-j] * dp[1][j] % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

int main(){
  cin >> N;
  A.resize(N);
  rep(i, N){
    cin >> A[i];
  }
  solve();
}
0