結果
問題 | No.3146 RE: Parentheses Counting |
ユーザー |
|
提出日時 | 2025-05-16 22:22:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 266 ms / 2,000 ms |
コード長 | 4,438 bytes |
コンパイル時間 | 2,107 ms |
コンパイル使用メモリ | 166,664 KB |
実行使用メモリ | 19,108 KB |
最終ジャッジ日時 | 2025-05-16 22:22:24 |
合計ジャッジ時間 | 14,467 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> #define fi first #define se second #define rep(i,s,n) for (int i = (s); i < (n); ++i) #define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define len(x) (int)(x).size() #define dup(x,y) (((x)+(y)-1)/(y)) #define pb push_back #define eb emplace_back #define Field(T) vector<vector<T>> using namespace std; using ll = long long; using ull = unsigned long long; template<typename T> using pq = priority_queue<T,vector<T>,greater<T>>; using P = pair<int,int>; template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;} template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;} template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { assert(x); int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; template< typename T > struct Combination { private: int n_; vector<T> fac, inv, finv; void extend(int l) { while(n_ <= l) { fac.emplace_back(fac.back() * T(n_)); inv.emplace_back(-inv[T::get_mod()%n_] * (T::get_mod()/n_)); finv.emplace_back(finv.back() * inv[n_]); ++n_; } } public: Combination() : n_(2), fac({T(1),T(1)}), inv({T(0),T(1)}), finv({T(1),T(1)}) {} // n! T fact(int n) { extend(n); return fac[n]; } // (n!)^{-1} T ifact(int n) { extend(n); return finv[n]; } // nCk T com(int n, int k) { if (n < 0 || k < 0 || n < k) return 0; extend(n); return fac[n] * finv[k] * finv[n-k]; } // nPk T perm(int n, int k) { if (n < 0 || k < 0 || n < k) return 0; extend(n); return fac[n] * finv[n-k]; } // nCk を Lucas の定理を用いて計算する。最悪 O(mod) であることに注意。 T com_lucas(long long n, long long k) { if (n < 0 || k < 0 || n < k) return 0; T ret = 1; const int p = T::get_mod(); while(n > 0 || k > 0) { ret *= com(n % p, k % p); n /= p, k /= p; } return ret; } }; using mint = ModInt<998244353>; int main() { // int n; // cin >> n; // vector<int> p(n, 0); // rep(i,n/2,n) p[i] = 1; // int ans = 0; // do { // int c = 0; // int ng = 0; // rep(i,0,n) { // c += 2*p[i]-1; // if (c < 0) ng = 1; // } // if (ng) continue; // // rep(i,0,n) cout << p[i]; // // cout << " -> "; // int x = 0; // rep(i,0,n) { // c += 2*p[i]-1; // if (i < n-1 && p[i] == 1 && p[i+1] == 0) { // x += c-1; // } // } // // cout << x << endl; // ans += x; // } while(next_permutation(all(p))); // cout << ans << endl; Combination<mint> com; vector<mint> p4(1000101); p4[0] = 1; rep(i,0,1000010) p4[i+1] = p4[i]*4; int t; cin >> t; while(t--) { int n; cin >> n; if (n%2 == 1) { cout << 0 << endl; continue; } n = n/2-1; mint ans = p4[n]; ans -= com.com(2*n+1,n); cout << ans << endl; } return 0; }