結果

問題 No.243 出席番号(2)
ユーザー shogier1shogier1
提出日時 2019-10-11 01:22:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,644 bytes
コンパイル時間 1,045 ms
コンパイル使用メモリ 98,832 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 11:19:14
合計ジャッジ時間 20,984 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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){
    ll x = kai[i];
    x *= (i+1);
    x %= MOD;
    kai[i+1] = (int)x;
  }
  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;
      ll x = dp[i&1][j];
      x *= cnt;
      x %= MOD;
      x += dp[(i+1)&1][j+1];
      x %= MOD;
      dp[(i+1)&1][j+1] = (int)x;
    }
    rep(j, 5005){
      dp[i&1][j] = 0;
    }
  }
  int ans = 0;
  rep(j, N+1){
    if(j & 1){
      ll x = ans;
      ll y = kai[N-j];
      y *= dp[1][j];
      y %= MOD;
      x = (x - y + MOD) % MOD;
      ans = x;
    }else{
      ll x = ans;
      ll y = kai[N-j];
      y *= dp[1][j];
      y %= MOD;
      x = (x + y) % MOD;
      ans = x;
    }
  }
  cout << ans << endl;
}

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