結果

問題 No.1961 Clear Brackets
ユーザー 👑 tute7627tute7627
提出日時 2022-05-15 17:58:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,762 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 211,272 KB
実行使用メモリ 23,892 KB
最終ジャッジ日時 2023-10-11 05:55:36
合計ジャッジ時間 7,425 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 WA -
testcase_15 AC 112 ms
20,528 KB
testcase_16 AC 83 ms
20,448 KB
testcase_17 WA -
testcase_18 AC 104 ms
20,588 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 76 ms
20,520 KB
testcase_22 AC 81 ms
20,532 KB
testcase_23 AC 108 ms
20,564 KB
testcase_24 AC 50 ms
20,448 KB
testcase_25 AC 126 ms
23,892 KB
testcase_26 AC 101 ms
21,040 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 136 ms
20,780 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 123 ms
20,532 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 107 ms
20,520 KB
testcase_40 WA -
testcase_41 AC 98 ms
20,520 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/segtree>
using namespace std;

int op_min(int a, int b){
  return min(a, b);
}

int e_min(){
  return (int)(1e9);
}

int op_max(int a, int b){
  return max(a, b);
}

int e_max(){
  return (int)(-1e9);
}

int main(){

  int N;
  cin >> N;
  string S;
  cin >> S;
  S += '?';
  N++;

  vector<int>max_r(N + 1);
  {
    vector<int>B(N + 1);
    for(int i = 0; i < N; i++){
      B[i + 1] = B[i] + (S[i] == ')' ? -1 : 1);
    }
    atcoder::segtree<int,op_min,e_min>seg(B);
    for(int i = 0; i < N; i++){
      auto judge = [&](int x){
        return x >= B[i];
      };
      max_r[i] = seg.max_right<decltype(judge)>(i, judge);
    }
  }
  vector<int>min_l(N + 1);
  {
    vector<int>B(N + 1);
    for(int i = 0; i < N; i++){
      B[i + 1] = B[i] + (S[i] == '(' ? 1 : -1);
    }
    atcoder::segtree<int,op_min,e_min>seg(B);
    for(int i = 0; i < N; i++){
      auto judge = [&](int x){
        return x >= B[i];
      };
      min_l[i] = seg.min_left<decltype(judge)>(i, judge);
    }
  }
  using Seg = atcoder::segtree<int,op_max,e_max>;
  vector<Seg> dp1(2, Seg(N + 1));
  vector<Seg> dp2(2, Seg(N + 1));
  dp1[0].set(0,0);
  vector<vector<int>>del(N + 2);
  for(int i = 0; i < N; i++){
    del[max_r[i]].push_back(i);
  }
  for(int r = 0; r < N; r++){
    for(auto l: del[r]){
      for(int j = 0; j < 2; j++){
        dp1[j].set(l, e_max());
        dp2[j].set(l, e_max());
      }
    }
    int mx1 = max(dp1[r % 2].get(r), dp1[r % 2].prod(min(r, min_l[r] + 1), r) + 1);
    int mx2 = max(dp2[r % 2].get(r), dp2[r % 2].prod(min_l[r], r) + 1);
    if(S[r] != '(')dp1[(r + 1) % 2].set(r + 1, mx1);
    if(S[r] != ')')dp2[(r + 1) % 2].set(r + 1, max(mx1, mx2));
  }
  cout << dp2[N % 2].get(N) << endl;
  return 0;
} 
0