Submission #13008808


Source Code Expand

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

bool check(vector<P> s) {
  int h = 0;
  for (P p : s) {
    int b = h+p.first;
    if (b < 0) return false;
    h += p.second;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<P> ls, rs;
  int total = 0;
  rep(i,n) {
    string s;
    cin >> s;
    int h = 0, b = 0;
    for (char c : s) {
      if (c == '(') ++h; else --h;
      b = min(b, h);
    }
    if (h > 0) ls.emplace_back(b, h);
    else rs.emplace_back(b-h, -h);
    total += h;
  }
  sort(ls.rbegin(), ls.rend());
  sort(rs.rbegin(), rs.rend());
  if (check(ls) && check(rs) && total == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Submission Info

Submission Time
Task F - Bracket Sequencing
User snuke
Language C++ (GCC 9.2.1)
Score 600
Code Size 835 Byte
Status AC
Exec Time 135 ms
Memory 18744 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 4
AC × 32
Set Name Test Cases
Sample sample_01, sample_02, sample_03, sample_04
All random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, random_13, random_21, random_22, random_23, random_31, random_32, random_33, random_41, random_42, random_43, random_51, random_52, random_53, random_61, random_62, random_63, sample_01, sample_02, sample_03, sample_04
Case Name Status Exec Time Memory
random_01 AC 60 ms 6996 KiB
random_02 AC 121 ms 16160 KiB
random_03 AC 75 ms 9036 KiB
random_04 AC 133 ms 18744 KiB
random_05 AC 135 ms 18740 KiB
random_06 AC 70 ms 10196 KiB
random_07 AC 30 ms 3964 KiB
random_08 AC 23 ms 3716 KiB
random_09 AC 21 ms 3544 KiB
random_10 AC 72 ms 10108 KiB
random_11 AC 2 ms 3564 KiB
random_12 AC 2 ms 3564 KiB
random_13 AC 2 ms 3488 KiB
random_21 AC 2 ms 3556 KiB
random_22 AC 2 ms 3580 KiB
random_23 AC 2 ms 3608 KiB
random_31 AC 2 ms 3560 KiB
random_32 AC 2 ms 3544 KiB
random_33 AC 2 ms 3608 KiB
random_41 AC 2 ms 3560 KiB
random_42 AC 2 ms 3604 KiB
random_43 AC 2 ms 3596 KiB
random_51 AC 2 ms 3500 KiB
random_52 AC 2 ms 3584 KiB
random_53 AC 2 ms 3604 KiB
random_61 AC 46 ms 5804 KiB
random_62 AC 53 ms 6824 KiB
random_63 AC 68 ms 9284 KiB
sample_01 AC 2 ms 3424 KiB
sample_02 AC 2 ms 3596 KiB
sample_03 AC 2 ms 3632 KiB
sample_04 AC 2 ms 3500 KiB