Submission #2337423


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
 
bool ok(vector< tuple< int, int > >& obj)
{
  int now = 0;
  for(auto v : obj) {
    if(now + get< 0 >(v) < 0) return(false);
    now += get< 1 >(v);
  }
  return(true);
}
 
int main()
{
  int N;
  cin >> N;
   
  vector< tuple< int, int > > curr, revv;
  while(N--) {
    string S;
    cin >> S;
 
    int height = 0, cnt = 0;
    for(char c : S) {
      if(c == '(') ++cnt;
      else         --cnt;
      height = min(height, cnt);
    }
    int revheight = 0, revcnt = 0;
    reverse(S.begin(), S.end());
    for(char c : S) {
      if(c == ')') ++revcnt;
      else         --revcnt;
      revheight = min(revheight, revcnt);
    }
    if(cnt >= 0) {
      curr.emplace_back(height, cnt);
    } else {
      revv.emplace_back(revheight, revcnt);
    }
  }
  sort(curr.rbegin(), curr.rend());
  sort(revv.rbegin(), revv.rend());
 
  bool flag = ok(curr) & ok(revv);
  int csum = 0, rsum = 0;
  for(auto v : curr) csum += get< 1 >(v);
  for(auto v : revv) rsum += get< 1 >(v);
  flag &= csum == rsum;
  if(flag) cout << "Yes" << endl;
  else     cout << "No"  << endl;
}

Submission Info

Submission Time
Task E - Parentheses
User ei13333
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1172 Byte
Status AC
Exec Time 2 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 94
Set Name Test Cases
All 00_sample_00, 00_sample_01, 01_minimal_00, 01_minimal_01, 01_minimal_02, 01_minimal_03, 10_detarame_00, 10_detarame_01, 10_detarame_02, 10_detarame_03, 10_detarame_04, 10_detarame_05, 10_detarame_06, 10_detarame_07, 10_detarame_08, 10_detarame_09, 20_tyotto_kasikoi_00, 20_tyotto_kasikoi_01, 20_tyotto_kasikoi_02, 20_tyotto_kasikoi_03, 20_tyotto_kasikoi_04, 20_tyotto_kasikoi_05, 20_tyotto_kasikoi_06, 20_tyotto_kasikoi_07, 20_tyotto_kasikoi_08, 20_tyotto_kasikoi_09, 20_tyotto_kasikoi_10, 20_tyotto_kasikoi_11, 20_tyotto_kasikoi_12, 20_tyotto_kasikoi_13, 20_tyotto_kasikoi_14, 20_tyotto_kasikoi_15, 20_tyotto_kasikoi_16, 20_tyotto_kasikoi_17, 20_tyotto_kasikoi_18, 20_tyotto_kasikoi_19, 30_ookii_00, 30_ookii_01, 30_ookii_02, 90_teuchi_00, 90_teuchi_01, 91_challenge_00, 91_challenge_01, 91_challenge_02, 91_challenge_03, 91_challenge_04, 91_challenge_05, d_00_sample_00, d_00_sample_01, d_01_minimal_00, d_01_minimal_01, d_01_minimal_02, d_01_minimal_03, d_10_detarame_00, d_10_detarame_01, d_10_detarame_02, d_10_detarame_03, d_10_detarame_04, d_10_detarame_05, d_10_detarame_06, d_10_detarame_07, d_10_detarame_08, d_10_detarame_09, d_20_tyotto_kasikoi_00, d_20_tyotto_kasikoi_01, d_20_tyotto_kasikoi_02, d_20_tyotto_kasikoi_03, d_20_tyotto_kasikoi_04, d_20_tyotto_kasikoi_05, d_20_tyotto_kasikoi_06, d_20_tyotto_kasikoi_07, d_20_tyotto_kasikoi_08, d_20_tyotto_kasikoi_09, d_20_tyotto_kasikoi_10, d_20_tyotto_kasikoi_11, d_20_tyotto_kasikoi_12, d_20_tyotto_kasikoi_13, d_20_tyotto_kasikoi_14, d_20_tyotto_kasikoi_15, d_20_tyotto_kasikoi_16, d_20_tyotto_kasikoi_17, d_20_tyotto_kasikoi_18, d_20_tyotto_kasikoi_19, d_30_ookii_00, d_30_ookii_01, d_30_ookii_02, d_90_teuchi_00, d_90_teuchi_01, d_91_challenge_00, d_91_challenge_01, d_91_challenge_02, d_91_challenge_03, d_91_challenge_04, d_91_challenge_05
Case Name Status Exec Time Memory
00_sample_00 AC 1 ms 256 KB
00_sample_01 AC 1 ms 256 KB
01_minimal_00 AC 1 ms 256 KB
01_minimal_01 AC 1 ms 256 KB
01_minimal_02 AC 1 ms 256 KB
01_minimal_03 AC 1 ms 256 KB
10_detarame_00 AC 1 ms 256 KB
10_detarame_01 AC 1 ms 256 KB
10_detarame_02 AC 1 ms 256 KB
10_detarame_03 AC 1 ms 256 KB
10_detarame_04 AC 1 ms 256 KB
10_detarame_05 AC 1 ms 256 KB
10_detarame_06 AC 1 ms 256 KB
10_detarame_07 AC 1 ms 256 KB
10_detarame_08 AC 1 ms 256 KB
10_detarame_09 AC 1 ms 256 KB
20_tyotto_kasikoi_00 AC 1 ms 256 KB
20_tyotto_kasikoi_01 AC 1 ms 256 KB
20_tyotto_kasikoi_02 AC 1 ms 256 KB
20_tyotto_kasikoi_03 AC 1 ms 256 KB
20_tyotto_kasikoi_04 AC 1 ms 256 KB
20_tyotto_kasikoi_05 AC 1 ms 256 KB
20_tyotto_kasikoi_06 AC 1 ms 256 KB
20_tyotto_kasikoi_07 AC 1 ms 256 KB
20_tyotto_kasikoi_08 AC 1 ms 256 KB
20_tyotto_kasikoi_09 AC 1 ms 256 KB
20_tyotto_kasikoi_10 AC 1 ms 256 KB
20_tyotto_kasikoi_11 AC 1 ms 256 KB
20_tyotto_kasikoi_12 AC 1 ms 256 KB
20_tyotto_kasikoi_13 AC 1 ms 256 KB
20_tyotto_kasikoi_14 AC 1 ms 256 KB
20_tyotto_kasikoi_15 AC 2 ms 256 KB
20_tyotto_kasikoi_16 AC 1 ms 256 KB
20_tyotto_kasikoi_17 AC 1 ms 256 KB
20_tyotto_kasikoi_18 AC 1 ms 256 KB
20_tyotto_kasikoi_19 AC 1 ms 256 KB
30_ookii_00 AC 2 ms 256 KB
30_ookii_01 AC 2 ms 256 KB
30_ookii_02 AC 2 ms 256 KB
90_teuchi_00 AC 1 ms 256 KB
90_teuchi_01 AC 1 ms 256 KB
91_challenge_00 AC 1 ms 256 KB
91_challenge_01 AC 1 ms 256 KB
91_challenge_02 AC 1 ms 256 KB
91_challenge_03 AC 1 ms 256 KB
91_challenge_04 AC 1 ms 256 KB
91_challenge_05 AC 1 ms 256 KB
d_00_sample_00 AC 1 ms 256 KB
d_00_sample_01 AC 1 ms 256 KB
d_01_minimal_00 AC 1 ms 256 KB
d_01_minimal_01 AC 1 ms 256 KB
d_01_minimal_02 AC 1 ms 256 KB
d_01_minimal_03 AC 1 ms 256 KB
d_10_detarame_00 AC 1 ms 256 KB
d_10_detarame_01 AC 1 ms 256 KB
d_10_detarame_02 AC 1 ms 256 KB
d_10_detarame_03 AC 1 ms 256 KB
d_10_detarame_04 AC 1 ms 256 KB
d_10_detarame_05 AC 1 ms 256 KB
d_10_detarame_06 AC 1 ms 256 KB
d_10_detarame_07 AC 1 ms 256 KB
d_10_detarame_08 AC 1 ms 256 KB
d_10_detarame_09 AC 1 ms 256 KB
d_20_tyotto_kasikoi_00 AC 1 ms 256 KB
d_20_tyotto_kasikoi_01 AC 1 ms 256 KB
d_20_tyotto_kasikoi_02 AC 1 ms 256 KB
d_20_tyotto_kasikoi_03 AC 1 ms 256 KB
d_20_tyotto_kasikoi_04 AC 1 ms 256 KB
d_20_tyotto_kasikoi_05 AC 1 ms 256 KB
d_20_tyotto_kasikoi_06 AC 1 ms 256 KB
d_20_tyotto_kasikoi_07 AC 1 ms 256 KB
d_20_tyotto_kasikoi_08 AC 1 ms 256 KB
d_20_tyotto_kasikoi_09 AC 1 ms 256 KB
d_20_tyotto_kasikoi_10 AC 1 ms 256 KB
d_20_tyotto_kasikoi_11 AC 1 ms 256 KB
d_20_tyotto_kasikoi_12 AC 1 ms 256 KB
d_20_tyotto_kasikoi_13 AC 1 ms 256 KB
d_20_tyotto_kasikoi_14 AC 1 ms 256 KB
d_20_tyotto_kasikoi_15 AC 1 ms 256 KB
d_20_tyotto_kasikoi_16 AC 1 ms 256 KB
d_20_tyotto_kasikoi_17 AC 1 ms 256 KB
d_20_tyotto_kasikoi_18 AC 1 ms 256 KB
d_20_tyotto_kasikoi_19 AC 1 ms 256 KB
d_30_ookii_00 AC 2 ms 256 KB
d_30_ookii_01 AC 2 ms 256 KB
d_30_ookii_02 AC 2 ms 256 KB
d_90_teuchi_00 AC 1 ms 256 KB
d_90_teuchi_01 AC 1 ms 256 KB
d_91_challenge_00 AC 1 ms 256 KB
d_91_challenge_01 AC 1 ms 256 KB
d_91_challenge_02 AC 1 ms 256 KB
d_91_challenge_03 AC 1 ms 256 KB
d_91_challenge_04 AC 1 ms 256 KB
d_91_challenge_05 AC 1 ms 256 KB