結果
| 問題 |
No.3099 Parentheses Decomposition
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-11 21:36:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 843 bytes |
| コンパイル時間 | 2,102 ms |
| コンパイル使用メモリ | 196,464 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-11 21:36:26 |
| 合計ジャッジ時間 | 5,101 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 9 WA * 11 |
ソースコード
#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using mint = atcoder::modint998244353;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MX = 500'010;
mint fact[MX + 10], finv[MX + 10];
mint C(ll a, ll b) {
if (a < b || a < 0 || b < 0)
return 0;
return fact[a] * finv[a - b] * finv[b];
}
void solve() {
fact[0] = finv[0] = 1;
rep(i, MX) {
fact[i + 1] = fact[i] * (i + 1);
finv[i + 1] = fact[i + 1].inv();
}
ll n;
string s;
cin >> n >> s;
mint ans = 0;
if (s[0] == '(' && s[1] == '(') {
rep(i, n / 2 + 1) ans += C(n / 2, i).pow(2);
} else {
ans = n;
}
cout << ans.val() << '\n';
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int T = 1;
for (int t = 0; t < T; t++) {
solve();
}
return 0;
}