結果
問題 | No.243 出席番号(2) |
ユーザー |
![]() |
提出日時 | 2019-10-11 01:33:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 585 ms / 2,000 ms |
コード長 | 1,655 bytes |
コンパイル時間 | 999 ms |
コンパイル使用メモリ | 100,156 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-22 08:18:42 |
合計ジャッジ時間 | 10,846 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#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 secondvoid 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^60int 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, N){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[N&1][j];y %= MOD;x = (x - y + MOD) % MOD;ans = (int)x;}else{ll x = ans;ll y = kai[N-j];y *= dp[N&1][j];y %= MOD;x = (x + y) % MOD;ans = (int)x;}}cout << ans << endl;}int main(){cin >> N;A.resize(N);rep(i, N){cin >> A[i];}solve();}