結果
| 問題 |
No.3099 Parentheses Decomposition
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-11 21:26:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 729 bytes |
| コンパイル時間 | 4,001 ms |
| コンパイル使用メモリ | 253,600 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-11 21:26:34 |
| 合計ジャッジ時間 | 4,339 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
vector<mint> fact(n + 1), inv(n + 1);
fact[0] = 1;
for(int i = 1; i <= n; i++) fact[i] = i * fact[i - 1];
inv[n] = fact[n].inv();
for(int i = n; i >= 1; i--) inv[i - 1] = i * inv[i];
auto binom = [&](int r, int c){
return fact[r] * inv[c] * inv[r - c];
};
mint ans;
if(s[1] == ')'){
ans = mint(2).pow(n / 2);
}else{
for(int i = 0; 2 * i <= n; i++){
ans += binom(n / 2, i) * binom(n / 2, i);
}
}
cout << ans.val() << '\n';
}