結果
問題 | No.243 出席番号(2) |
ユーザー |
![]() |
提出日時 | 2015-12-20 02:57:23 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 188 ms / 2,000 ms |
コード長 | 3,724 bytes |
コンパイル時間 | 909 ms |
コンパイル使用メモリ | 104,744 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-17 11:18:17 |
合計ジャッジ時間 | 3,925 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <iostream>#include <algorithm>#include <cmath>#include <vector>#include <complex>#include <queue>#include <deque>#include <set>#include <map>#include <unordered_set>#include <unordered_map>#include <iomanip>#include <assert.h>#include <array>#include <cstdio>#include <cstring>#include <random>#include <functional>#include <numeric>#include <bitset>using namespace std;#define REP(i,a,b) for(int i=a;i<(int)b;i++)#define rep(i,n) REP(i,0,n)#define all(c) (c).begin(), (c).end()#define zero(a) memset(a, 0, sizeof a)#define minus(a) memset(a, -1, sizeof a)#define minimize(a, x) a = std::min(a, x)#define maximize(a, x) a = std::max(a, x)typedef long long ll;int const inf = 1<<29;template<class value_type, int MOD>class ModInt {private:value_type val_;static value_type mod_pow(value_type x, value_type n, value_type mo) { value_type ret = 1; while(n > 0) { if(n & 1) { ret = ret * x % mo; } x = x *x % mo; n >>= 1; } return ret; }public:ModInt() { val_ = 0; }ModInt(value_type x) { val_ = (x % MOD + MOD) % MOD; }ModInt const operator + (ModInt const& rhs) const {return std::move(ModInt(val_+rhs.get()));}ModInt const operator - (ModInt const& rhs) const {return std::move(ModInt(val_-rhs.get()));}ModInt const operator * (ModInt const& rhs) const {return std::move(ModInt(val_*rhs.get()));}ModInt const operator / (ModInt const& rhs) const {return std::move(ModInt(val_*mod_pow(rhs.get(), MOD-2, MOD))); // fermat theorem}friend ModInt const operator + (value_type lhs, ModInt const& rhs) {return std::move(ModInt(lhs+rhs.get()));}friend ModInt const operator - (value_type lhs, ModInt const& rhs) {return std::move(ModInt(lhs-rhs.get()));}friend ModInt const operator * (value_type lhs, ModInt const& rhs) {return std::move(ModInt(lhs*rhs.get()));}friend ModInt const operator / (value_type lhs, ModInt const& rhs) {return std::move(ModInt(lhs*mod_pow(rhs.get(), MOD-2, MOD))); // fermat theorem}ModInt operator += (ModInt const& rhs) {return *this = ModInt(val_+rhs.get()).get();}ModInt operator -= (ModInt const& rhs) {return *this = ModInt(val_-rhs.get()).get();}ModInt operator *= (ModInt const& rhs) {return *this = ModInt(val_*rhs.get()).get();}ModInt operator /= (ModInt const& rhs) {return *this = ModInt(val_*mod_pow(rhs.get(), MOD-2, MOD)).get();}bool operator == (ModInt const& rhs) const {return val_ == rhs.get();}value_type const get() const { return val_; }value_type & get() { return val_; }friend ostream& operator << (ostream& ost, ModInt const& x) {return ost << x.get();}friend istream& operator >> (istream& ist, ModInt& x) {string s; ist >> s;int size = s.size();x.get() = 0;rep(i, size) {x.get() *= 10;x.get() += s[i]-'0';x.get() %= MOD;}return ist;}};typedef ModInt<long long, 1000000007> mint;vector<mint> dp(5050);vector<mint> P(5050);int ngnums[5050];int main() {int N; cin >> N;rep(i, N) { int a; cin >> a; ngnums[a]++; }dp[0] = 1;rep(i, N) for(int j=N-1; j>=0; j--)dp[j + 1] += dp[j] * ngnums[i]; // i1がダメな生徒 ∨ i2がダメな生徒 ∨ ...P[0] = 1; REP(i, 1, N+1) P[i] = P[i-1] * i;mint ans = 0;// ダメな割当のない自由な割当 = 完全に自由な割当 - 1人だけダメな割当 + 2人だけダメな割当 - 3人だけダメな割当 + ... + (-1)^k k人ダメな割当 + ... (-1)^N N人ダメな割当rep(i, N+1) {ans += (i % 2 == 0 ? +1 : -1) * dp[i] * P[N - i];}cout << ans << endl;return 0;}