結果
問題 | No.93 ペガサス |
ユーザー | Komaki__ |
提出日時 | 2014-12-07 22:17:02 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,156 bytes |
コンパイル時間 | 1,634 ms |
コンパイル使用メモリ | 162,624 KB |
実行使用メモリ | 19,328 KB |
最終ジャッジ日時 | 2024-06-11 17:41:59 |
合計ジャッジ時間 | 2,711 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
19,200 KB |
testcase_01 | AC | 6 ms
19,200 KB |
testcase_02 | AC | 7 ms
19,304 KB |
testcase_03 | AC | 8 ms
19,180 KB |
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 | AC | 7 ms
19,072 KB |
testcase_18 | AC | 7 ms
19,200 KB |
testcase_19 | WA | - |
ソースコード
#ifdef KOMAKI_LOCAL #include <omp.h> #else #define NDEBUG #endif #include <bits/stdc++.h> #include <sys/time.h> #include <unistd.h> using namespace std; #define i64 int64_t #define rep(i, n) for(i64 i = 0; i < ((i64)(n)); ++i) #define sz(v) ((i64)((v).size())) #define bit(n) (((i64)1)<<((i64)(n))) #define all(v) (v).begin(), (v).end() /******************************************************************/ /* */ /* Undefine "GF_USE_FIXED_GF" to use various mods, but slower. */ /* To use fixed one, set your mod at "static const int mod = ;" */ /* */ /******************************************************************/ #define GF_USE_FIXED_GF template <typename T> class GF { public: #ifdef GF_USE_FIXED_GF static const T mod = 1e9 + 7; // Set your mod! GF() { permutation_memo = std::vector<T>(1, 1); inverse_memo = std::vector<T>(2, 1); permutation_inverse_memo = std::vector<T>(2, 1); } #else T mod; GF(T mod) : mod(mod) { permutation_memo = std::vector<T>(1, 1); inverse_memo = std::vector<T>(2, 1); permutation_inverse_memo = std::vector<T>(2, 1); } #endif T norm(T i); T add(T i0, T i1); T sub(T i0, T i1); T mul(T i0, T i1); T div(T i0, T i1); T pow(T i, int64_t p); T inv(T i); T permInv(T i); T permutation(T n, T m); // n * (n - 1) * ... * (n - m + 1), Non limited memorization, Avoid segmentation fault! T combination(T n, T m); // Memorized for n < MEMO_SIZE_LIMIT. private: static const int MEMO_SIZE_LIMIT = 2000000; std::vector<T> permutation_memo; std::vector<T> inverse_memo; std::vector<T> permutation_inverse_memo; }; template <typename T> inline T GF<T>::permutation(T n, T m) { if(m < 0 || n < m) return 0; while(permutation_memo.size() <= n){ permutation_memo.push_back(mul(permutation_memo.back(), permutation_memo.size())); } return mul(permutation_memo[n], permInv(n - m)); } template <typename T> inline T GF<T>::combination(T n, T m) { if(m < 0 || n < m) return 0; if(n - m < m) m = n - m; if(n < MEMO_SIZE_LIMIT){ T num = permutation(n, n); T den = mul(permInv(m), permInv(n - m)); return mul(num, den); } T num = 1, den = 1; for(T i = 0; i < m; ++i){ num = mul(num, n - i); den = mul(den, i + 1); } return div(num, den); } template <typename T> inline T GF<T>::norm(T i) { return (i % mod + mod) % mod; } template <typename T> inline T GF<T>::add(T i0, T i1) { T res = i0 + i1; if(mod <= res) return res - mod; return res; } template <typename T> inline T GF<T>::sub(T i0, T i1) { T res = i0 - i1; if(res < 0) return res + mod; return res; } template <typename T> inline T GF<T>::mul(T i0, T i1) { return (int64_t)i0 * i1 % mod; } template <typename T> inline T GF<T>::div(T i0, T i1) { return mul(i0, inv(i1)); } template <typename T> inline T GF<T>::permInv(T i) { while(permutation_inverse_memo.size() <= i){ permutation_inverse_memo.push_back(mul(permutation_inverse_memo.back(), inv(permutation_inverse_memo.size()))); } return permutation_inverse_memo[i]; } template <typename T> inline T GF<T>::inv(T i) { if(i < MEMO_SIZE_LIMIT){ while(inverse_memo.size() <= i){ // Deformation of formula. // b[t] * t = (M - (M / t) * t) * b[M - (M / t) * t]; // Divides by i over a finite field GF(mod), b[t] = - (M / t) * b[M % t]. int size = inverse_memo.size(); inverse_memo.push_back(mod - (int64_t)(mod / size) * inverse_memo[mod % size] % mod); } return inverse_memo[i]; } return this->pow(i, mod - 2); } template <typename T> inline T GF<T>::pow(T i, int64_t p) { T res = 1; for(; p; p >>= 1){ if(p & 1) res = mul(res, i); i = mul(i, i); } return res; } const i64 N = 1005; const i64 MOD = 1e9 + 7; i64 dp[N][N]; i64 sub_dp[N][N]; i64 recur(i64 pos, i64 rem); i64 subRecur(i64 pos, i64 rem) { if(pos < 0) return 0; if(rem == 0) return 1; if(pos == 0) return 0; i64 &res = sub_dp[pos][rem]; if(res != -1) return res; return res = (recur(pos, rem) + subRecur(pos - 1, rem - 1)) % MOD; } i64 recur(i64 pos, i64 rem) { if(pos < 0) return 0; if(rem == 0) return 1; if(pos == 0) return 0; i64 &res = dp[pos][rem]; if(res != -1) return res; res = recur(pos - 1, rem - 0); res = (res + subRecur(pos - 2, rem - 1) * 2) % MOD; return res; } int main() { memset(dp, -1, sizeof(dp)); memset(sub_dp, -1, sizeof(sub_dp)); i64 n; cin >> n; i64 ans = 0; GF<int> gf; rep(i, n){ i64 k = gf.permutation(n - i, n - i); i64 way = 0; for(i64 use = 0; use <= i; ++use) way = way + recur(n / 2, use) * recur(n - n / 2, i - use) % MOD; ans += k * way % MOD * (i % 2 == 0 ? 1 : -1); } cout << (ans % MOD + MOD) % MOD << endl; }