結果
問題 | No.336 門松列列 |
ユーザー | koyumeishi |
提出日時 | 2016-01-16 00:06:27 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 2,835 bytes |
コンパイル時間 | 750 ms |
コンパイル使用メモリ | 91,048 KB |
実行使用メモリ | 4,372 KB |
最終ジャッジ日時 | 2023-09-02 18:44:40 |
合計ジャッジ時間 | 1,876 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
4,372 KB |
testcase_01 | AC | 2 ms
4,372 KB |
testcase_02 | AC | 1 ms
4,372 KB |
testcase_03 | AC | 2 ms
4,368 KB |
testcase_04 | AC | 65 ms
4,372 KB |
testcase_05 | AC | 1 ms
4,372 KB |
testcase_06 | AC | 9 ms
4,368 KB |
testcase_07 | AC | 24 ms
4,368 KB |
testcase_08 | AC | 42 ms
4,368 KB |
testcase_09 | AC | 62 ms
4,368 KB |
testcase_10 | AC | 64 ms
4,372 KB |
testcase_11 | AC | 63 ms
4,368 KB |
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <functional> #include <set> #include <ctime> #include <random> using namespace std; template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;} template<class T> istream& operator , (istream& is, T& val){ return is >> val;} template<class T> ostream& operator << (ostream& os, vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"\n":" ");return os;} template<class T> ostream& operator , (ostream& os, T& val){ return os << " " << val;} template<class T> ostream& operator >> (ostream& os, T& val){ return os << " " << val;} bool is_kadomatsu_sequence(vector<int> x){ if(x.size() != 3) return false; if(x[0] < x[1] && x[1] > x[2] && x[2] != x[0]) return true; if(x[0] > x[1] && x[1] < x[2] && x[2] != x[0]) return true; return false; } #define MOD 1000000007 long long inv; // nCk mod p, O(1) // precomputation O(size) class combination_mod{ const long long mod; const long long size; vector<long long> fact; //n! vector<long long> fact_inv; // (n!)^-1 void make_fact(){ fact[0] = 1; for(long long i=1; i<size; i++){ fact[i] = fact[i-1]*i % mod; } } void make_fact_inv(){ fact_inv[0] = fact_inv[1] = 1; for(long long i=2; i<size; i++){ fact_inv[i] = fact_inv[mod%i] * (mod - mod/i) % mod; // x ^ -1 } for(int i=2; i<size; i++){ fact_inv[i] = fact_inv[i-1] * fact_inv[i] % mod; // x! ^ -1 } inv = fact_inv[2]; } public: combination_mod(long long mod_, long long size_ = 2000000) : mod(mod_), size(size_+1){ fact.resize(size); fact_inv.resize(size); make_fact(); make_fact_inv(); } //nCk mod p O(1) long long comb(long long n, long long k){ if(k==0 || n==k) return 1; long long ret = fact[n] * fact_inv[k] % mod * fact_inv[n-k] % mod; return ret; } }; int main(){ int n; cin >> n; if(n<3){ cout << 0 << endl; return 0; } combination_mod cmb(MOD, 3000); vector<long long> E(n+100, -1); E[0] = E[1] = 1; E[2] = 1; long long ans = 0; for(int i=2; i<n; i++){ long long tmp = 0; for(int j=0; j<=i; j++){ tmp += (cmb.comb(i,j) * E[j] % MOD) * E[i-j] % MOD; tmp %= MOD; } tmp = (tmp*inv) % MOD; E[i+1] = tmp; } cout << (E[n]*2)%MOD << endl; /* vector<int> a(n); int cnt = 0; iota(a.begin(), a.end(), 0); do{ bool ok = true; deque<int> dq; for(int i=0; i<n; i++){ dq.push_back(a[i]); while(dq.size()>3) dq.pop_front(); if(dq.size() == 3){ if(is_kadomatsu_sequence({dq[0],dq[1],dq[2]})){ }else{ ok = false; } } } if(ok){ cnt++; } }while(next_permutation(a.begin(), a.end())); cout << cnt << endl; */ return 0; }