結果
問題 |
No.3146 RE: Parentheses Counting
|
ユーザー |
![]() |
提出日時 | 2025-03-13 17:56:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 137 ms / 2,000 ms |
コード長 | 1,386 bytes |
コンパイル時間 | 1,898 ms |
コンパイル使用メモリ | 196,400 KB |
実行使用メモリ | 40,724 KB |
最終ジャッジ日時 | 2025-05-16 20:52:23 |
合計ジャッジ時間 | 9,343 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define MOD 998244353LL using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; vector<ll> powers = {1}; vector<ll> inv = {1, 1}; vector<ll> fact = {1}; vector<ll> invfact = {1}; while (T--) { int N; cin >> N; if (N % 2 == 1) cout << "0\n"; else { if (N == 2) cout << "0\n"; else { N = N / 2 - 1; while (powers.size() <= 2 * N) { powers.push_back(powers[powers.size() - 1] * 2 % MOD); } while (fact.size() <= 2 * N + 1) { ll x = fact.size(); if (inv.size() == fact.size()) { inv.push_back((-(MOD / x) * inv[MOD % x]) % MOD + MOD); inv[x] %= MOD; } fact.push_back(fact[fact.size() - 1] * x % MOD); invfact.push_back(invfact[invfact.size() - 1] * inv[x] % MOD); } ll ans = powers[2 * N] - ((fact[2 * N + 1] * invfact[N] % MOD) * invfact[N + 1]) % MOD; if (ans < 0) ans += MOD; cout << ans << "\n"; } } } }