結果
| 問題 |
No.2031 Colored Brackets
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2022-08-05 22:50:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 380 ms / 2,000 ms |
| コード長 | 982 bytes |
| コンパイル時間 | 3,828 ms |
| コンパイル使用メモリ | 236,016 KB |
| 実行使用メモリ | 144,384 KB |
| 最終ジャッジ日時 | 2024-09-15 20:15:42 |
| 合計ジャッジ時間 | 6,666 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
//using mint = modint1000000007;
using mint = modint998244353;
map<pair<int,int>,mint> dp[3005];
int main(){
int N;
cin >> N;
string S;
cin >> S;
dp[0][make_pair(0,0)] = 1;
rep(i,N){
FOR(it,dp[i]){
mint x = it->second;
int j = (it->first).first;
int k = (it->first).second;
if(S[i] == '('){
dp[i+1][make_pair(j+1,k)] += x;
dp[i+1][make_pair(j,k+1)] += x;
}
if(S[i] == ')'){
if(j-1>=0) dp[i+1][make_pair(j-1,k)] += x;
if(k-1>=0) dp[i+1][make_pair(j,k-1)] += x;
}
}
}
cout << dp[N][make_pair(0,0)].val() << endl;
return 0;
}
どらら