結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 WA -
testcase_15 AC 113 ms
20,612 KB
testcase_16 WA -
testcase_17 AC 115 ms
20,864 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 112 ms
20,516 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 109 ms
20,472 KB
testcase_24 WA -
testcase_25 AC 128 ms
24,036 KB
testcase_26 WA -
testcase_27 AC 104 ms
20,516 KB
testcase_28 WA -
testcase_29 AC 136 ms
21,028 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 98 ms
21,132 KB
testcase_33 AC 90 ms
21,048 KB
testcase_34 AC 112 ms
21,564 KB
testcase_35 AC 104 ms
20,656 KB
testcase_36 WA -
testcase_37 AC 126 ms
23,692 KB
testcase_38 AC 123 ms
20,984 KB
testcase_39 WA -
testcase_40 AC 131 ms
20,864 KB
testcase_41 WA -
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_l[r], r) + 1);
    int mx2 = max(dp2[r % 2].get(r), dp2[r % 2].prod(max(0, min_l[r] - 2), 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