結果

問題 No.2031 Colored Brackets
ユーザー どららどらら
提出日時 2022-08-05 22:50:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 392 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 3,789 ms
コンパイル使用メモリ 233,420 KB
実行使用メモリ 144,348 KB
最終ジャッジ日時 2023-10-14 00:26:13
合計ジャッジ時間 7,756 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 57 ms
24,384 KB
testcase_05 AC 22 ms
11,332 KB
testcase_06 AC 34 ms
15,548 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 91 ms
37,564 KB
testcase_09 AC 127 ms
50,412 KB
testcase_10 AC 171 ms
66,328 KB
testcase_11 AC 127 ms
50,776 KB
testcase_12 AC 188 ms
72,580 KB
testcase_13 AC 88 ms
36,820 KB
testcase_14 AC 193 ms
73,852 KB
testcase_15 AC 196 ms
74,728 KB
testcase_16 AC 191 ms
73,968 KB
testcase_17 AC 392 ms
144,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 4 ms
4,580 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 3 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

0