結果
問題 | No.2668 Trees on Graph Paper |
ユーザー | k1suxu |
提出日時 | 2024-03-09 00:15:17 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 7,378 bytes |
コンパイル時間 | 2,579 ms |
コンパイル使用メモリ | 250,548 KB |
実行使用メモリ | 550,296 KB |
最終ジャッジ日時 | 2024-09-29 21:01:44 |
合計ジャッジ時間 | 44,459 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | MLE | - |
testcase_02 | MLE | - |
testcase_03 | MLE | - |
testcase_04 | MLE | - |
testcase_05 | MLE | - |
testcase_06 | MLE | - |
testcase_07 | MLE | - |
testcase_08 | MLE | - |
testcase_09 | MLE | - |
testcase_10 | MLE | - |
testcase_11 | MLE | - |
testcase_12 | MLE | - |
testcase_13 | MLE | - |
testcase_14 | MLE | - |
testcase_15 | MLE | - |
testcase_16 | MLE | - |
testcase_17 | MLE | - |
testcase_18 | MLE | - |
testcase_19 | MLE | - |
testcase_20 | MLE | - |
testcase_21 | MLE | - |
testcase_22 | MLE | - |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
testcase_27 | MLE | - |
testcase_28 | MLE | - |
testcase_29 | MLE | - |
testcase_30 | MLE | - |
testcase_31 | MLE | - |
testcase_32 | MLE | - |
ソースコード
// #pragma GCC target("avx") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) #define FOR(n) for(int i = 0; i < (int)n; i++) #define repi(i,a,b) for(int i = (int)a; i < (int)b; i++) #define all(x) x.begin(),x.end() //#define mp make_pair #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vvvvi vector<vvvi> #define pii pair<int,int> #define vpii vector<pair<int,int>> template<typename T> bool chmax(T &a, const T b) {if(a<b) {a=b; return true;} else {return false;}} template<typename T> bool chmin(T &a, const T b) {if(a>b) {a=b; return true;} else {return false;}} using ll = long long; using ld = long double; using ull = unsigned long long; const ll INF = numeric_limits<long long>::max() / 2; const ld pi = 3.1415926535897932384626433832795028; const ll mod = 998244353; int dx[] = {1, 0, -1, 0, -1, -1, 1, 1}; int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; #define int long long struct Arbitrary_Modular_Int { long long x; Arbitrary_Modular_Int() = default; Arbitrary_Modular_Int(long long x_) : x(x_ >= 0 ? x_ % get_mod() : (get_mod() - (-x_) % get_mod()) % get_mod()) {} // static long long& get_mod() { // static long long mod = 0; // return mod; // } static long long& get_mod() { static long long mod = 0; return mod; } static void set_mod(long long mod_) { get_mod() = mod_; } long long val() const { return (x%get_mod()+get_mod())%get_mod(); } Arbitrary_Modular_Int& operator^=(long long d) { Arbitrary_Modular_Int ret(1); long long nx = x; while(d) { if(d&1) ret *= nx; (nx *= nx) %= get_mod(); d >>= 1; } *this = ret; return *this; } Arbitrary_Modular_Int operator^(long long d) const {return Arbitrary_Modular_Int(*this) ^= d;} Arbitrary_Modular_Int pow(long long d) const {return Arbitrary_Modular_Int(*this) ^= d;} //use this basically // Arbitrary_Modular_Int inv() const { // return Arbitrary_Modular_Int(*this) ^ (get_mod()-2); // } //only if the module number is not prime //Don't use. This is broken. Arbitrary_Modular_Int inv() const { long long a = (x%get_mod()+get_mod())%get_mod(), b = get_mod(), u = 1, v = 0; while(b > 0) { long long t = a/b; a -= t*b, swap(a, b); u -= t*v, swap(u, v); } return Arbitrary_Modular_Int(u); } Arbitrary_Modular_Int& operator+=(const Arbitrary_Modular_Int other) { if((x += other.x) >= get_mod()) x -= get_mod(); return *this; } Arbitrary_Modular_Int& operator-=(const Arbitrary_Modular_Int other) { if((x -= other.x) < 0) x += get_mod(); return *this; } Arbitrary_Modular_Int& operator*=(const Arbitrary_Modular_Int other) { long long z = x; z *= other.x; z %= get_mod(); x = z; if(x < 0) x += get_mod(); return *this; } Arbitrary_Modular_Int& operator/=(const Arbitrary_Modular_Int other) { return *this = *this * other.inv(); } Arbitrary_Modular_Int& operator++() { x++; if (x == get_mod()) x = 0; return *this; } Arbitrary_Modular_Int& operator--() { if (x == 0) x = get_mod(); x--; return *this; } Arbitrary_Modular_Int operator+(const Arbitrary_Modular_Int other) const {return Arbitrary_Modular_Int(*this) += other;} Arbitrary_Modular_Int operator-(const Arbitrary_Modular_Int other) const {return Arbitrary_Modular_Int(*this) -= other;} Arbitrary_Modular_Int operator*(const Arbitrary_Modular_Int other) const {return Arbitrary_Modular_Int(*this) *= other;} Arbitrary_Modular_Int operator/(const Arbitrary_Modular_Int other) const {return Arbitrary_Modular_Int(*this) /= other;} Arbitrary_Modular_Int& operator+=(const long long other) {Arbitrary_Modular_Int other_(other); *this += other_; return *this;} Arbitrary_Modular_Int& operator-=(const long long other) {Arbitrary_Modular_Int other_(other); *this -= other_; return *this;} Arbitrary_Modular_Int& operator*=(const long long other) {Arbitrary_Modular_Int other_(other); *this *= other_; return *this;} Arbitrary_Modular_Int& operator/=(const long long other) {Arbitrary_Modular_Int other_(other); *this /= other_; return *this;} Arbitrary_Modular_Int operator+(const long long other) const {return Arbitrary_Modular_Int(*this) += other;} Arbitrary_Modular_Int operator-(const long long other) const {return Arbitrary_Modular_Int(*this) -= other;} Arbitrary_Modular_Int operator*(const long long other) const {return Arbitrary_Modular_Int(*this) *= other;} Arbitrary_Modular_Int operator/(const long long other) const {return Arbitrary_Modular_Int(*this) /= other;} bool operator==(const Arbitrary_Modular_Int other) const {return (*this).val() == other.val();} bool operator!=(const Arbitrary_Modular_Int other) const {return (*this).val() != other.val();} bool operator==(const long long other) const {return (*this).val() == other;} bool operator!=(const long long other) const {return (*this).val() != other;} Arbitrary_Modular_Int operator-() const {return Arbitrary_Modular_Int(0LL)-Arbitrary_Modular_Int(*this);} //-1: sqrtが存在しない //複数存在する場合どれを返すかは不明 long long get_sqrt() { long long a = val(), p = get_mod(); if(a == 0) return 0; if(p == 2) return a; if(Arbitrary_Modular_Int(a).pow((p - 1) >> 1).val() != 1) return -1; long long b = 1; while(Arbitrary_Modular_Int(b).pow((p - 1) >> 1).val() == 1) ++b; long long e = 0, m = p - 1; while(m % 2 == 0) m >>= 1, ++e; long long x = Arbitrary_Modular_Int(a).pow((m - 1) >> 1).val(); long long y = a * (x * x % p) % p; (x *= a) %= p; long long z = Arbitrary_Modular_Int(b).pow(m).val(); while(y != 1) { long long j = 0, t = y; while(t != 1) { j += 1; (t *= t) %= p; } z = Arbitrary_Modular_Int(z).pow((long long)1 << (e - j - 1)).val(); (x *= z) %= p; (z *= z) %= p; (y *= z) %= p; e = j; } return x; } }; istream& operator>>(istream& is, Arbitrary_Modular_Int& x) { long long X; is >> X; x = X; return is; } ostream& operator<<(ostream& os, Arbitrary_Modular_Int& x) { os << x.val(); return os; } using mint = Arbitrary_Modular_Int; void solve() { const int MX = 1e7; int n, m; cin >> n >> m; mint::set_mod(m); vector<vector<mint>> dp(MX+1, vector<mint>(3, 0)); dp[1][0] = 1, dp[1][1] = 1, dp[1][2] = 1; repi(i, 1, MX) { dp[i+1][0] += dp[i][0] + dp[i][1]*(i+1); dp[i+1][1] += dp[i][0] + dp[i][1] + dp[i][2]*(i+1); dp[i+1][2] += dp[i][0] + dp[i][1] + dp[i][2]; } mint ans = 1; repi(i, 1, 2*n) ans *= i; repi(i, 1, n) ans *= dp[i*2-1][2]; cout << ans.val() << endl; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }