結果
問題 | No.2106 Wild Cacco |
ユーザー | Sumitacchan |
提出日時 | 2022-09-03 18:10:20 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 451 ms / 2,000 ms |
コード長 | 1,426 bytes |
コンパイル時間 | 4,211 ms |
コンパイル使用メモリ | 240,332 KB |
実行使用メモリ | 222,336 KB |
最終ジャッジ日時 | 2024-12-30 11:43:33 |
合計ジャッジ時間 | 14,948 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/convolution> #include <atcoder/modint> using namespace std; using namespace atcoder; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define REP(i, n) FOR(i,0,n) using mint = modint998244353; int main(){ string s; cin >> s; if(s.size() % 2 != 0){ cout << 0 << endl; return 0; } int n = s.size() / 2; vector<vector<vector<mint>>> dp(n + 1, vector<vector<mint>>(n + 1, vector<mint>(2, 0))); dp[0][0][0] = 1; REP(i, n + 1) REP(j, i + 1){ int pos = i + j; if(pos == 2 * n) continue; const char c = s[pos]; REP(k, 2){ // '(' if((c == '(' || c == '.') && i + 1 <= n){ dp[i + 1][j][k] += dp[i][j][k]; } // ')' if((c == ')' || c == '.') && j + 1 <= i){ dp[i][j + 1][k] += dp[i][j][k]; } // '{' if((c == '?' || c == '.') && i + 1 <= n){ if(k == 0) dp[i + 1][j][k] += dp[i][j][k]; } // '}' if((c == '?' || c == '.') && j + 1 <= i){ dp[i][j + 1][1] += dp[i][j][k]; } } } mint ans = dp[n][n][0] + dp[n][n][1]; cout << ans.val() << endl; return 0; }